Program.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace StressClient
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. try
  14. {
  15. System.Console.WriteLine("Begin YouYan Stress test...");
  16. ConnectionManager cm = new ConnectionManager();
  17. // 线程列表
  18. List<Thread> thread_list = new List<Thread>();
  19. // 循环添加连接客户端
  20. for (int i = 0; i < 100; i++)
  21. {
  22. int mn = 100000 + i;
  23. string clientId = $"iwb{mn:D6}";
  24. //DotnetSocketClient _client = new DotnetSocketClient(clientId);
  25. AsyncClient _client = new AsyncClient(i, clientId);
  26. // 创建线程,使之执行该类的Run方法
  27. Thread oThread = new Thread(new ThreadStart(_client.Run));
  28. oThread.Start();
  29. cm.Add(oThread);
  30. }
  31. /*Alpha oAlpha = new Alpha();
  32. Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));
  33. oThread.Start();*/
  34. while (true)
  35. {
  36. string cmd = System.Console.ReadLine();
  37. if (cmd.CompareTo("quit") == 0)
  38. break;
  39. }
  40. // 停止工作线程
  41. cm.Stop();
  42. }
  43. catch(Exception e)
  44. {
  45. System.Console.WriteLine(e.Message);
  46. }
  47. System.Console.WriteLine("Enter any key to stop");
  48. System.Console.ReadKey();
  49. }
  50. }
  51. }