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
Reverse String
Programmer DNA
Big numbers
test
My Test
Lazy exception caching
s
Việc Làm
never use floats for money
Plt-D v.0.8.1