Guest User

Untitled

a guest
Jan 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. private async void btnTestConn_Click(object sender, EventArgs e)
  2. {
  3. async Task<bool> test_networkAsync()
  4. {
  5. Stopwatch sw = new Stopwatch();
  6. try
  7. {
  8. //sw.Start();
  9. using (var client = new System.Net.WebClient())
  10. using (var stream = await client.OpenReadTaskAsync("https://www.youtube.com"))
  11. {
  12. //sw.Stop();
  13. //Console.WriteLine(sw.Elapsed);
  14. return true;
  15. }
  16. }
  17. catch
  18. {
  19. return false;
  20. }
  21. }
  22.  
  23. // I put it in the loop in order to testing.
  24. for (int i = 0; i < 5; ++i)
  25. {
  26. await test_networkAsync();
  27. }
  28. }
Add Comment
Please, Sign In to add comment