private void Initialize() { base.Name = "ThreadPool"; this.ValidateSTPStartInfo(); this._isSuspended = this._stpStartInfo.StartSuspended; if (this._stpStartInfo.PerformanceCounterInstanceName != null) { try { this._windowsPCs = new STPInstancePerformanceCounters(this._stpStartInfo.PerformanceCounterInstanceName); } catch (Exception) { this._windowsPCs = NullSTPInstancePerformanceCounters.Instance; } } if (this._stpStartInfo.EnableLocalPerformanceCounters) { this._localPCs = new LocalSTPInstancePerformanceCounters(); } if (!this._isSuspended) { this.StartOptimalNumberOfThreads(); } }
/// <summary> /// Constructor /// </summary> public SmartThreadPool() { this._name = "SmartThreadPool"; this._workerThreads = Hashtable.Synchronized(new Hashtable()); this._workItemsQueue = new WorkItemsQueue(); this._stpStartInfo = new STPStartInfo(); this._isIdleWaitHandle = new ManualResetEvent(true); this._shuttingDownEvent = new ManualResetEvent(false); this._workItemsGroups = Hashtable.Synchronized(new Hashtable()); this._pcs = NullSTPInstancePerformanceCounters.Instance; this.Initialize(); }
private void Initialize() { this.ValidateSTPStartInfo(); if (this._stpStartInfo.PerformanceCounterInstanceName != null) { try { this._pcs = new STPInstancePerformanceCounters(this._stpStartInfo.PerformanceCounterInstanceName); } catch (Exception) { this._pcs = NullSTPInstancePerformanceCounters.Instance; } } this.StartOptimalNumberOfThreads(); }
private void Initialize() { ValidateSTPStartInfo(); // _stpStartInfoRW stores a read/write copy of the STPStartInfo. // Actually only MaxWorkerThreads and MinWorkerThreads are overwritten _isSuspended = _stpStartInfo.StartSuspended; if (_stpStartInfo.EnableLocalPerformanceCounters) { _localPCs = new LocalSTPInstancePerformanceCounters(); } // If the STP is not started suspended then start the threads. if (!_isSuspended) { StartOptimalNumberOfThreads(); } }
// Token: 0x060017E7 RID: 6119 // RVA: 0x00073E3C File Offset: 0x0007203C private void Initialize() { base.Name = this._stpStartInfo.ThreadPoolName; this.ValidateSTPStartInfo(); this._isSuspended = this._stpStartInfo.StartSuspended; if (this._stpStartInfo.PerformanceCounterInstanceName != null) { try { this._windowsPCs = new STPInstancePerformanceCounters(this._stpStartInfo.PerformanceCounterInstanceName); } catch (Exception) { this._windowsPCs = NullSTPInstancePerformanceCounters.Instance; } } if (this._stpStartInfo.EnableLocalPerformanceCounters) { this._localPCs = new LocalSTPInstancePerformanceCounters(); } if (!this._isSuspended) { this.StartOptimalNumberOfThreads(); } }
// Token: 0x060017F5 RID: 6133 // RVA: 0x00074654 File Offset: 0x00072854 public void Shutdown(bool bool_0, int int_0) { this.ValidateNotDisposed(); ISTPInstancePerformanceCounters windowsPCs = this._windowsPCs; if (NullSTPInstancePerformanceCounters.Instance != this._windowsPCs) { this._windowsPCs = NullSTPInstancePerformanceCounters.Instance; windowsPCs.Dispose(); } Thread[] array; lock (this._workerThreads.SyncRoot) { this._workItemsQueue.Dispose(); this._shutdown = true; this._shuttingDownEvent.Set(); array = new Thread[this._workerThreads.Count]; this._workerThreads.Keys.CopyTo(array, 0); } int num = int_0; Stopwatch stopwatch = Stopwatch.StartNew(); bool flag = -1 == int_0; bool flag2 = false; Thread[] array2 = array; int i = 0; while (i < array2.Length) { Thread thread = array2[i]; if (flag || num >= 0) { if (thread.Join(num)) { if (!flag) { num = int_0 - (int)stopwatch.ElapsedMilliseconds; } i++; continue; } flag2 = true; } else { flag2 = true; } IL_E1: if (flag2 && bool_0) { Thread[] array3 = array; for (int j = 0; j < array3.Length; j++) { Thread thread2 = array3[j]; if (thread2 != null && thread2.IsAlive) { try { thread2.Abort(); } catch (SecurityException ex) { ex.GetHashCode(); } catch (ThreadStateException ex2) { ex2.GetHashCode(); } } } } return; } goto IL_E1; }
/// <summary> /// Empties the queue of work items and abort the threads in the pool. /// </summary> private void Shutdown(bool forceAbort, int millisecondsTimeout) { ValidateNotDisposed(); ISTPInstancePerformanceCounters pcs = _windowsPCs; if (NullSTPInstancePerformanceCounters.Instance != _windowsPCs) { // Set the _pcs to "null" to stop updating the performance // counters _windowsPCs = NullSTPInstancePerformanceCounters.Instance; pcs.Dispose(); } Thread[] threads; lock (_workerThreads.SyncRoot) { // Shutdown the work items queue _workItemsQueue.Dispose(); // Signal the threads to exit _shutdown = true; _shuttingDownEvent.Set(); // Make a copy of the threads' references in the pool threads = new Thread[_workerThreads.Count]; _workerThreads.Keys.CopyTo(threads, 0); } int millisecondsLeft = millisecondsTimeout; Stopwatch stopwatch = Stopwatch.StartNew(); //DateTime start = DateTime.UtcNow; bool waitInfinitely = (Timeout.Infinite == millisecondsTimeout); bool timeout = false; // Each iteration we update the time left for the timeout. foreach (Thread thread in threads) { // Join don't work with negative numbers if (!waitInfinitely && (millisecondsLeft < 0)) { timeout = true; break; } // Wait for the thread to terminate bool success = thread.Join(millisecondsLeft); if (!success) { timeout = true; break; } if (!waitInfinitely) { // Update the time left to wait //TimeSpan ts = DateTime.UtcNow - start; millisecondsLeft = millisecondsTimeout - (int)stopwatch.ElapsedMilliseconds; } } if (timeout && forceAbort) { // Abort the threads in the pool foreach (Thread thread in threads) { if ((thread != null) && thread.IsAlive ) { try { thread.Abort(); // Shutdown } catch (SecurityException e) { e.GetHashCode(); } catch (ThreadStateException ex) { ex.GetHashCode(); // In case the thread has been terminated // after the check if it is alive. } } } } }
/// <summary> /// Empties the queue of work items and abort the threads in the pool. /// </summary> public void Shutdown(bool forceAbort, int millisecondsTimeout) { ValidateNotDisposed(); ISTPInstancePerformanceCounters pcs = _pcs; if (NullSTPInstancePerformanceCounters.Instance != _pcs) { _pcs.Dispose(); // Set the _pcs to "null" to stop updating the performance // counters _pcs = NullSTPInstancePerformanceCounters.Instance; } Thread [] threads = null; lock(_workerThreads.SyncRoot) { // Shutdown the work items queue _workItemsQueue.Dispose(); // Signal the threads to exit _shutdown = true; _shuttingDownEvent.Set(); // Make a copy of the threads' references in the pool threads = new Thread [_workerThreads.Count]; _workerThreads.Keys.CopyTo(threads, 0); } int millisecondsLeft = millisecondsTimeout; DateTime start = DateTime.Now; bool waitInfinitely = (Timeout.Infinite == millisecondsTimeout); bool timeout = false; // Each iteration we update the time left for the timeout. foreach(Thread thread in threads) { // Join don't work with negative numbers if (!waitInfinitely && (millisecondsLeft < 0)) { timeout = true; break; } // Wait for the thread to terminate bool success = thread.Join(millisecondsLeft); if(!success) { timeout = true; break; } if(!waitInfinitely) { // Update the time left to wait TimeSpan ts = DateTime.Now - start; millisecondsLeft = millisecondsTimeout - (int)ts.TotalMilliseconds; } } if (timeout && forceAbort) { // Abort the threads in the pool foreach(Thread thread in threads) { if ((thread != null) && thread.IsAlive) { try { thread.Abort("Shutdown"); } catch(SecurityException e) { e.GetHashCode(); } catch(ThreadStateException ex) { ex.GetHashCode(); // In case the thread has been terminated // after the check if it is alive. } } } } // Dispose of the performance counters pcs.Dispose(); }
private void Initialize() { ValidateSTPStartInfo(); if (null != _stpStartInfo.PerformanceCounterInstanceName) { try { _pcs = new STPInstancePerformanceCounters(_stpStartInfo.PerformanceCounterInstanceName); } catch(Exception e) { Debug.WriteLine("Unable to create Performance Counters: " + e.ToString()); _pcs = NullSTPInstancePerformanceCounters.Instance; } } StartOptimalNumberOfThreads(); }
/// <summary> /// Empties the queue of work items and abort the threads in the pool. /// </summary> public void Shutdown(bool forceAbort, int millisecondsTimeout) { this.ValidateNotDisposed(); ISTPInstancePerformanceCounters counters = this._pcs; if (NullSTPInstancePerformanceCounters.Instance != this._pcs) { this._pcs.Dispose(); this._pcs = NullSTPInstancePerformanceCounters.Instance; } Thread[] array = null; lock (this._workerThreads.SyncRoot) { this._workItemsQueue.Dispose(); this._shutdown = true; this._shuttingDownEvent.Set(); array = new Thread[this._workerThreads.Count]; this._workerThreads.Keys.CopyTo(array, 0); } int num = millisecondsTimeout; DateTime now = DateTime.Now; bool flag = -1 == millisecondsTimeout; bool flag2 = false; foreach (Thread thread in array) { if (!flag && (num < 0)) { flag2 = true; break; } if (!thread.Join(num)) { flag2 = true; break; } if (!flag) { TimeSpan span = (TimeSpan)(DateTime.Now - now); num = millisecondsTimeout - ((int)span.TotalMilliseconds); } } if (flag2 && forceAbort) { foreach (Thread thread2 in array) { if ((thread2 != null) && thread2.IsAlive) { try { thread2.Abort("Shutdown"); } catch (SecurityException exception) { exception.GetHashCode(); } catch (ThreadStateException exception2) { exception2.GetHashCode(); } } } } counters.Dispose(); }
public void Shutdown(bool forceAbort, int millisecondsTimeout) { this.ValidateNotDisposed(); ISTPInstancePerformanceCounters windowsPCs = this._windowsPCs; if (NullSTPInstancePerformanceCounters.Instance != this._windowsPCs) { this._windowsPCs = NullSTPInstancePerformanceCounters.Instance; windowsPCs.Dispose(); } object syncRoot; Monitor.Enter(syncRoot = this._workerThreads.SyncRoot); Thread[] array; try { this._workItemsQueue.Dispose(); this._shutdown = true; this._shuttingDownEvent.Set(); array = new Thread[this._workerThreads.Count]; this._workerThreads.Keys.CopyTo(array, 0); } finally { Monitor.Exit(syncRoot); } int num = millisecondsTimeout; System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); bool flag = -1 == millisecondsTimeout; bool flag2 = false; Thread[] array2 = array; for (int i = 0; i < array2.Length; i++) { Thread thread = array2[i]; if (!flag && num < 0) { flag2 = true; break; } if (!thread.Join(num)) { flag2 = true; break; } if (!flag) { num = millisecondsTimeout - (int)stopwatch.ElapsedMilliseconds; } } if (flag2 && forceAbort) { Thread[] array3 = array; for (int j = 0; j < array3.Length; j++) { Thread thread2 = array3[j]; if (thread2 != null && thread2.IsAlive) { try { thread2.Abort(); } catch (SecurityException ex) { ex.GetHashCode(); } catch (ThreadStateException ex2) { ex2.GetHashCode(); } } } } }