[Bartender]TaskEngines.GetEnumerator Method

TaskEngines.GetEnumerator Method

Gets the enumerator used to iterate through the collection.
Namespace: Seagull.BarTender.PrintServer
Assembly: Seagull.BarTender.Print (in Seagull.BarTender.Print.dll) Version: 2016 R1

public IEnumerator GetEnumerator()
Return Value
Type: IEnumerator
Implements
IEnumerable.GetEnumerator()
Examples
The following example demonstrates how to use the GetEnumerator interface of TaskEngines to visit each TaskEngine held within a TaskManager.

public void Demo()
{
   // Initialize a new TaskManager object.
   using (TaskManager btTaskManager = new TaskManager())
   {
      // Start a few task engines.
      btTaskManager.Start(3);

      // Create some printing tasks to be distributed between the engines.
      PrintLabelFormatTask[] tasks = new PrintLabelFormatTask[4];
      tasks[0] = new PrintLabelFormatTask(@"C:\Format1.btw");
      tasks[1] = new PrintLabelFormatTask(@"C:\Format2.btw");
      tasks[2] = new PrintLabelFormatTask(@"C:\Format3.btw");
      tasks[3] = new PrintLabelFormatTask(@"C:\Format4.btw");

      // Enqueue the tasks.
      foreach (PrintLabelFormatTask t in tasks)
         btTaskManager.TaskQueue.QueueTask(t);

      // Stop the task engines as they finish up.
      while (btTaskManager.TaskEngines.BusyCount > 0)
      {
         // For each engine that is running, but not busy, terminate it
         // (foreach implicitly uses GetEnumerator).
         foreach (TaskEngine e in btTaskManager.TaskEngines)
            if (e.IsAlive && e.Status != TaskEngineStatus.Busy)
               e.Terminate();
         System.Threading.Thread.Sleep(1000);
      }

      // Make sure that all engines are stopped.
      if (btTaskManager.TaskEngines.AliveCount > 0)
         btTaskManager.Stop(10000, true);
   }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章