private static void DoAsyncPrivate(IList dataCollection, int threadCn, WaitCallback processItemMethod, DoGetObjTask getObjMethod, bool needWaitAll, bool hasReturnValue, out Hashtable processResult)
 {
     if (dataCollection == null)
     {
         throw new ArgumentNullException("dataCollection");
     }
     if (threadCn >= 64 || threadCn < 2)
     {
         throw new ArgumentOutOfRangeException("threadCn", "threadCn 参数必须在2和64之间");
     }
     if (threadCn > dataCollection.Count)
     {
         threadCn = dataCollection.Count;
     }
     IList[] listArray = (IList[])new ArrayList[threadCn];
     AsyncHelper.DataWithStateList dataWithStates = new AsyncHelper.DataWithStateList();
     AutoResetEvent[] autoResetEventArray         = new AutoResetEvent[threadCn];
     for (int index = 0; index < threadCn; ++index)
     {
         listArray[index]           = (IList) new ArrayList();
         autoResetEventArray[index] = new AutoResetEvent(false);
     }
     for (int index1 = 0; index1 < dataCollection.Count; ++index1)
     {
         object data   = dataCollection[index1];
         int    index2 = index1 % threadCn;
         listArray[index2].Add(data);
         dataWithStates.Add(new AsyncHelper.DataWithState(data, AsyncHelper.ProcessState.WaitForProcess));
     }
     AsyncHelper.AsyncContext context = AsyncHelper.AsyncContext.GetContext(threadCn, dataWithStates, needWaitAll, hasReturnValue, processItemMethod, getObjMethod);
     for (int index = 0; index < threadCn; ++index)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncHelper.DoPrivate), (object)new object[3]
         {
             (object)listArray[index],
             (object)context,
             (object)autoResetEventArray[index]
         });
     }
     if (needWaitAll)
     {
         WaitHandle.WaitAll((WaitHandle[])autoResetEventArray);
     }
     else
     {
         WaitHandle.WaitAny((WaitHandle[])autoResetEventArray);
         context.SetBreakSignal();
     }
     processResult = context.ProcessResult;
 }
Exemple #2
0
 private static void DoAsyncPrivate(IList dataCollection, int threadCn, WaitCallback processItemMethod, DoGetObjTask getObjMethod, bool needWaitAll, bool hasReturnValue, out Hashtable processResult)
 {
     if (dataCollection == null)
     {
         throw new ArgumentNullException("dataCollection");
     }
     if (threadCn >= 64 || threadCn < 2)
     {
         throw new ArgumentOutOfRangeException("threadCn", "threadCn 参数必须在2和64之间");
     }
     if (threadCn > dataCollection.Count)
     {
         threadCn = dataCollection.Count;
     }
     IList[] array = new ArrayList[threadCn];
     AsyncHelper.DataWithStateList dataWithStateList = new AsyncHelper.DataWithStateList();
     AutoResetEvent[] array2 = new AutoResetEvent[threadCn];
     for (int i = 0; i < threadCn; i++)
     {
         array[i]  = new ArrayList();
         array2[i] = new AutoResetEvent(false);
     }
     for (int j = 0; j < dataCollection.Count; j++)
     {
         object obj = dataCollection[j];
         int    num = j % threadCn;
         array[num].Add(obj);
         dataWithStateList.Add(new AsyncHelper.DataWithState(obj, AsyncHelper.ProcessState.WaitForProcess));
     }
     AsyncHelper.AsyncContext context = AsyncHelper.AsyncContext.GetContext(threadCn, dataWithStateList, needWaitAll, hasReturnValue, processItemMethod, getObjMethod);
     for (int k = 0; k < threadCn; k++)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncHelper.DoPrivate), new object[]
         {
             array[k],
             context,
             array2[k]
         });
     }
     if (needWaitAll)
     {
         WaitHandle.WaitAll(array2);
     }
     else
     {
         WaitHandle.WaitAny(array2);
         context.SetBreakSignal();
     }
     processResult = context.ProcessResult;
 }