Esempio n. 1
0
        public void Shutdown()
        {
            List <Thread> threads = null;

            lock (this.syncObj)
            {
                if (this.state != AsyncProcessor.State.Running)
                {
                    throw new InvalidOperationException("AsyncProcessor must be running before it can be stopped");
                }
                this.state = AsyncProcessor.State.ShutdownPending;
                threads    = new List <Thread>(this.workerThreads);
                this.workerThreads.Clear();
            }
            for (int i = 0; i < this.maxConcurrent; i++)
            {
                this.semaphore.Release();
            }
            foreach (Thread thread in threads)
            {
                thread.Join();
            }
            lock (this.syncObj)
            {
                this.state = AsyncProcessor.State.Shutdown;
            }
        }
Esempio n. 2
0
 public void Initialize()
 {
     lock (this.syncObj)
     {
         if (this.state != AsyncProcessor.State.Shutdown)
         {
             throw new InvalidOperationException("AsyncProcessor must be shutdown before it can be started");
         }
         for (int i = 0; i < this.maxConcurrent; i++)
         {
             Thread thread = new Thread(new ThreadStart(this.WorkerThreadMainLoop));
             thread.Start();
             this.workerThreads.Add(thread);
         }
         this.state = AsyncProcessor.State.Running;
     }
 }