From 17f4f597068acf0559870a47e5af4413a4aa61f9 Mon Sep 17 00:00:00 2001 From: Michal Staszewski Date: Tue, 21 Jun 2011 14:15:17 +0200 Subject: [PATCH] CHG: STP threads can now be foreground (cherry picked from commit b29bd9578aa4b9ec6b84137ae5ab00d0a410c8e0) --- SmartThreadPool/STPStartInfo.cs | 15 +++++++++++++++ SmartThreadPool/SmartThreadPool.cs | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SmartThreadPool/STPStartInfo.cs b/SmartThreadPool/STPStartInfo.cs index c4a8e07..fdab702 100644 --- a/SmartThreadPool/STPStartInfo.cs +++ b/SmartThreadPool/STPStartInfo.cs @@ -13,6 +13,7 @@ namespace Amib.Threading private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority; private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; + private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground; private bool _enableLocalPerformanceCounters; public STPStartInfo() @@ -33,6 +34,7 @@ namespace Amib.Threading _threadPriority = stpStartInfo.ThreadPriority; _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName; _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters; + _areThreadsBackground = stpStartInfo.AreThreadsBackground; } @@ -123,6 +125,19 @@ namespace Amib.Threading } } + /// + /// Get/Set backgroundness of thread in thread pool. + /// + public virtual bool AreThreadsBackground + { + get { return _areThreadsBackground; } + set + { + ThrowIfReadOnly (); + _areThreadsBackground = value; + } + } + /// /// Get a readonly version of this STPStartInfo. /// diff --git a/SmartThreadPool/SmartThreadPool.cs b/SmartThreadPool/SmartThreadPool.cs index 2b0202f..9853d72 100644 --- a/SmartThreadPool/SmartThreadPool.cs +++ b/SmartThreadPool/SmartThreadPool.cs @@ -164,6 +164,11 @@ namespace Amib.Threading /// It is relevant only to QueueWorkItem of Action<...>/Func<...> /// public const bool DefaultFillStateWithArgs = false; + + /// + /// The default thread backgroundness. (true) + /// + public const bool DefaultAreThreadsBackground = true; #endregion @@ -608,7 +613,7 @@ namespace Amib.Threading // Configure the new thread and start it workerThread.Name = "STP " + Name + " Thread #" + _threadCounter; - workerThread.IsBackground = true; + workerThread.IsBackground = _stpStartInfo.AreThreadsBackground; #if !(_SILVERLIGHT) workerThread.Priority = _stpStartInfo.ThreadPriority; #endif