/// <summary>
 /// Executes the enumeration task
 /// </summary>
 public void ExecuteTask()
 {
     try
     {
         //Create a local link list for the current task
         LinkableLinkedList batch = new LinkableLinkedList();
         int batchPosition        = 0;
         while (!sharedState.disposed && enumerator.MoveNext())
         {
             batch.AppendValue(enumerator.Current);
             //If the position within the enumerator reached batch size add it to the accumulated linked list
             if (++batchPosition == batchSize)
             {
                 lock (sharedState.syncObject)
                 {
                     AppendListToAccumulatedList(batch);
                     //Reset batch
                     batchPosition = 0;
                     batch         = new LinkableLinkedList();
                 }
             }
         }
         //Add last batch if needed
         if (batchPosition > 0)
         {
             AppendListToAccumulatedList(batch);
         }
         //If this is the last task, set state if sharedState to done
         if (Interlocked.Increment(ref sharedState.enumeratorsDoneCount) == sharedState.numberOfEnumerateTask)
         {
             lock (sharedState.syncObject)
             {
                 sharedState.allEnumeratorsDone = true;
                 Monitor.PulseAll(sharedState.syncObject);
             }
         }
     }
     catch (Exception ex)
     {
         //On any exception update the shared state
         lock (sharedState.syncObject)
         {
             sharedState.exceptionOccured = ex;
             Monitor.PulseAll(sharedState.syncObject);
         }
     }
 }
 /// <summary>
 /// Executes the enumeration task
 /// </summary>
 public void ExecuteTask()
 {
     try
     {
         //Create a local link list for the current task
         LinkableLinkedList batch = new LinkableLinkedList();
         int batchPosition = 0;
         while (!sharedState.disposed && enumerator.MoveNext())
         {
             batch.AppendValue(enumerator.Current);
             //If the position within the enumerator reached batch size add it to the accumulated linked list
             if (++batchPosition == batchSize)
             {
                 lock (sharedState.syncObject)
                 {
                     AppendListToAccumulatedList(batch);
                     //Reset batch
                     batchPosition = 0;
                     batch = new LinkableLinkedList();
                 }
             }
         }
         //Add last batch if needed
         if (batchPosition > 0)
         {
             AppendListToAccumulatedList(batch);
         }
         //If this is the last task, set state if sharedState to done
         if (Interlocked.Increment(ref sharedState.enumeratorsDoneCount) == sharedState.numberOfEnumerateTask)
         {
             lock (sharedState.syncObject)
             {
                 sharedState.allEnumeratorsDone = true;
                 Monitor.PulseAll(sharedState.syncObject);
             }
         }
     }
     catch (Exception ex)
     {
         //On any exception update the shared state
         lock (sharedState.syncObject)
         {
             sharedState.exceptionOccured = ex;
             Monitor.PulseAll(sharedState.syncObject);
         }
     }
 }