示例#1
0
            /// <summary>
            /// Purge worker pool by removing all workers that are currently stopped (not working).
            /// <br /><br />
            /// Returns amount of workers removed this way.
            /// </summary>
            /// <returns></returns>
            public int Purge()
            {
                int count = 0;

                foreach (T o in GetArray())
                {
                    if (null == o)
                    {
                        continue;
                    }
                    bool remove = false;
                    if (o is Energy.Interface.IWorker)
                    {
                        Energy.Interface.IWorker w = o as Energy.Interface.IWorker;
                        if (!w.Running)
                        {
                            remove = true;
                        }
                    }
                    if (remove)
                    {
                        Remove(o);
                        count++;
                    }
                }
                return(count);
            }
示例#2
0
 public void Stop()
 {
     foreach (T o in GetArray())
     {
         if (null == o)
         {
             continue;
         }
         if (o is Energy.Interface.IWorker)
         {
             Energy.Interface.IWorker w = o as Energy.Interface.IWorker;
             w.Stop();
         }
     }
 }
示例#3
0
 public void Spawn()
 {
     try
     {
         T o = Activator.CreateInstance <T>();
         _List.Add(o);
         if (o is Energy.Interface.IWorker)
         {
             Energy.Interface.IWorker worker = o as Energy.Interface.IWorker;
             worker.Start();
         }
     }
     catch (MissingMethodException)
     {
         System.Diagnostics.Debug.WriteLine("Missing method for constructing new object for spawn");
     }
 }
示例#4
0
 private bool GetRunning()
 {
     foreach (T o in GetArray())
     {
         if (null == o)
         {
             continue;
         }
         if (o is Energy.Interface.IWorker)
         {
             Energy.Interface.IWorker w = o as Energy.Interface.IWorker;
             if (w.Running)
             {
                 return(true);
             }
         }
     }
     return(false);
 }