Exemplo n.º 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);
     }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 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;
      }
 }
Exemplo n.º 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;
 }