Beispiel #1
0
 private static ThreadPoolThread GetThread()
 {
     lock (_Threads)
     {
         foreach (ThreadPoolThread thread in _Threads)
         {
             if (!thread.IsBusy)
             {
                 thread.IsBusy = true;
                 return(thread);
             }
         }
         if (_Threads.Count < _maxThreadCount)
         {
             var thread = new ThreadPoolThread {
                 IsBusy = true
             };
             _Threads.Add(thread);
             return(thread);
         }
         return(null);
     }
 }
Beispiel #2
0
 internal static bool NotifyThreadIdle(ThreadPoolThread thread)
 {
     lock (_Threads)
     {
         if (_Threads.Count > _maxThreadCount)
         {
             thread.Dispose();
             _Threads.Remove(thread);
             Debug.WriteLine("ThreadPool thread stoped: #" + _Threads.Count);
             return(false);
         }
     }
     // start next enqueued item
     lock (_ItemsQueue.SyncRoot)
     {
         if (_ItemsQueue.Count > 0)
         {
             thread.Item = _ItemsQueue.Dequeue() as ThreadPoolItem;
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
 private static ThreadPoolThread GetThread()
 {
     lock (_Threads)
      {
     foreach (ThreadPoolThread thread in _Threads)
     {
        if (!thread.IsBusy)
        {
           thread.IsBusy = true;
           return thread;
        }
     }
     if (_Threads.Count < _maxThreadCount)
     {
        var thread = new ThreadPoolThread {IsBusy = true};
        _Threads.Add(thread);
        return thread;
     }
     return null;
      }
 }
Beispiel #4
0
 internal static bool NotifyThreadIdle(ThreadPoolThread thread)
 {
     lock (_Threads)
      {
     if (_Threads.Count > _maxThreadCount)
     {
        thread.Dispose();
        _Threads.Remove(thread);
        Debug.Print("ThreadPool thread stoped: #" + _Threads.Count);
        return false;
     }
      }
      // start next enqueued item
      lock (_ItemsQueue.SyncRoot)
      {
     if (_ItemsQueue.Count > 0)
     {
        thread.Item = _ItemsQueue.Dequeue() as ThreadPoolItem;
        return true;
     }
      }
      return false;
 }