Program.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Net.Http;
  4. using System.Net.Http.Headers;
  5. using System.Threading.Tasks;
  6. namespace Test
  7. {
  8. internal static class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. var httpClient = new HttpClient() { BaseAddress = new Uri("http://www.hbtswl.com") };
  13. httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Mozilla/5.0"));
  14. var res = httpClient.GetAsync("/").Result;
  15. var statusCode = res.StatusCode;
  16. Console.WriteLine(statusCode);
  17. }
  18. public static ConcurrentDictionary<string, object> LockDic { get; set; } = new ConcurrentDictionary<string, object>();
  19. public static int Count { get; set; }
  20. public static async Task<string> Test()
  21. {
  22. //using (new AsyncLock(LockDic.GetOrAdd("aa", new object())).LockAsync())
  23. {
  24. await Task.Run(() =>
  25. {
  26. for (int i = 0; i < 100; i++)
  27. {
  28. Count++;
  29. }
  30. });
  31. await Task.Run(() =>
  32. {
  33. for (int i = 0; i < 100; i++)
  34. {
  35. Count--;
  36. }
  37. });
  38. return "";
  39. }
  40. }
  41. }
  42. }