示例#1
0
 /// <summary>
 /// 设置Worker线程数量
 /// </summary>
 /// <param name="count">普通Task线程数</param>
 /// <param name="slowCount">执行时间较长的Task线程数</param>
 public void SetWorkerCount(int count, int slowCount)
 {
     foreach (Thread i in threadpool)
     {
         ClientManager.RemoveThread(i.Name);
         i.Abort();
     }
     threadpool.Clear();
     for (int i = 0; i < count; i++)
     {
         Thread thread = new Thread(Worker)
         {
             Priority = ThreadPriority.Highest
         };
         thread.Name = string.Format("Worker({0})", thread.ManagedThreadId);
         ClientManager.AddThread(thread);
         thread.Start();
         threadpool.Add(thread);
     }
     for (int i = 0; i < slowCount; i++)
     {
         Thread thread = new Thread(WorkerSlow);
         thread.Name = string.Format("WorkerSlow({0})", thread.ManagedThreadId);
         ClientManager.AddThread(thread);
         thread.Start();
         threadpool.Add(thread);
     }
 }
示例#2
0
 /// <summary>
 /// 启动任务管理器线程池
 /// </summary>
 public void Start()
 {
     if (main != null)
     {
         ClientManager.RemoveThread(main.Name);
         main.Abort();
     }
     main      = new Thread(MainLoop);
     main.Name = string.Format("ThreadPoolMainLoop({0})", main.ManagedThreadId);
     ClientManager.AddThread(main);
     main.Start();
 }