Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Get a webpage - the async way
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Net.Http; using System.Threading.Tasks; using System.Threading; namespace Rextester { public class Program { public static async void Main(string[] args) { ThreadPool.QueueUserWorkItem(f => RequestData("http://google.com")); Thread.Sleep(2000); } static async void RequestData(string uri) { using (var client = new HttpClient()) { Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId); Console.WriteLine(await client.GetStringAsync(uri)); //how's that differs from sync code? The thread is not being used while IO occurs. Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId); //note - different thread, that was started only when IO finished. } } } }
run
|
edit
|
history
|
help
0
codetility CyclicRotation
Math 9.4
C# - a method that accepts an indefinite number of parameters
Compare 2 int
test
InvokeProgram
Encapsulation and abstration
two words are anagrams
Exception handling2
asxasxscdf