예제 #1
0
 public void AddTask(AsyncResult asyncResult, ChartDataArgument2 argument, WaitCallback funcToCreateChartData)
 {
     lock (this._TaskLock)
     {
         TaskOfCreateChartData2 task = new TaskOfCreateChartData2(argument, funcToCreateChartData);
         bool needQueueWorkItem = this._WorkItemNumber <= 3;//so, up to 3 thread will be created
         this._Tasks.Enqueue(task);
         if (needQueueWorkItem)
         {
             this._WorkItemNumber++;
             ThreadPool.QueueUserWorkItem(this.CreateChartData, null);
         }
     }
 }
 public void AddTask(AsyncResult asyncResult, ChartDataArgument2 argument, WaitCallback funcToCreateChartData)
 {
     lock (this._TaskLock)
     {
         var  task = new TaskOfCreateChartData2(argument, funcToCreateChartData);
         bool needQueueWorkItem = this._WorkItemNumber <= MaxThreadCount;
         this._Tasks.Enqueue(task);
         if (needQueueWorkItem)
         {
             this._WorkItemNumber++;
             ThreadPool.QueueUserWorkItem(this.CreateChartData, null);
         }
     }
 }
 private void CreateChartData(object state)
 {
     while (true)
     {
         TaskOfCreateChartData2 task = null;
         lock (this._TaskLock)
         {
             if (this._Tasks.Count > 0)
             {
                 task = this._Tasks.Dequeue();
             }
             else
             {
                 this._WorkItemNumber--;
                 break;
             }
         }
         task.FuncToCreateChartData(task.ArgumentOfCreateChartData);
     }
 }