Class CMSThread
Wrapper class for System.Threading.Thread object with additional log and context item possibilities.
public sealed class CMSThread : AbstractWorker
- Inheritance
-
objectCMSThread
- Inherited Members
- Extension Methods
Remarks
Based on the UseEmptyContext flag, the CMSThread starts with empty context items or copies context items from the parent thread. Only context items based on the AbstractContext<TContext> class are copied.
Constructors
CMSThread(ThreadStart)
Creates new instance of CMSThread.
public CMSThread(ThreadStart start)
Parameters
start
ThreadStartThread start method
CMSThread(ThreadStart, ThreadSettings)
Creates new instance of CMSThread.
public CMSThread(ThreadStart start, ThreadSettings settings)
Parameters
start
ThreadStartA System.Threading.ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
settings
ThreadSettingsSettings object with required behavior of CMSThread object. The
settings
object must not be modified.
CMSThread(ThreadStart, bool, ThreadModeEnum)
Creates new instance of CMSThread.
[Obsolete("Member is deprecated and will be removed in next version.")]
[ObsoleteSince(28, 0)]
public CMSThread(ThreadStart start, bool createLog = false, ThreadModeEnum mode = ThreadModeEnum.Async)
Parameters
start
ThreadStartThread start method
createLog
boolIndicates whether thread should create it's own log.
mode
ThreadModeEnumThread mode
Properties
AllowAsyncActions
Indicates if new threads can be created within this thread. (By default no new threads are created.)
public bool AllowAsyncActions { get; set; }
Property Value
- bool
ConnectionString
Connection string name that the thread should use to access the database
public string ConnectionString { get; set; }
Property Value
- string
IsBackground
Defines if a thread is a background thread
public bool IsBackground { get; }
Property Value
- bool
Log
Logs for long running operations.
[Obsolete("Member is deprecated and will be removed in next version.")]
[ObsoleteSince(28, 0)]
public ILogContext Log { get; }
Property Value
Mode
If true, the thread runs synchronously
public ThreadModeEnum Mode { get; }
Property Value
Priority
Specifies the scheduling priority.
public ThreadPriority Priority { get; }
Property Value
- ThreadPriority
RunningThreads
Counter of running Threads.
[Obsolete("Property was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static IPerformanceCounter RunningThreads { get; }
Property Value
ThreadFinished
Time when the thread finished.
public DateTime ThreadFinished { get; }
Property Value
- DateTime
ThreadGUID
Thread GUID.
public Guid ThreadGUID { get; }
Property Value
- Guid
ThreadID
Thread ID.
public int ThreadID { get; }
Property Value
- int
ThreadStarted
Time when the thread started.
public DateTime ThreadStarted { get; }
Property Value
- DateTime
Methods
AllowEmptyContext(CMSThread)
Allows anonymous thread to use new dedicated context in subsequent calls. Call this method in case the anonymous thread isn't initiated from a request thread, or in case you want to start with an empty thread context on purpose.
public static void AllowEmptyContext(CMSThread thread = null)
Parameters
thread
CMSThreadThread for which to allow the empty context. Pass null for current thread.
GetCurrentThreadId()
Gets the current thread ID
public static int GetCurrentThreadId()
Returns
- int
GetThread(Guid)
Finds the thread based on the given GUID.
[Obsolete("Method was not intended for public use and will be removed.")]
[ObsoleteSince(29, 3)]
public static CMSThread GetThread(Guid threadGuid)
Parameters
threadGuid
GuidThread GUID
Returns
Join()
Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.
public void Join()
- See Also
-
Join()
LoadTargetDelegateInfo(Delegate)
Sets the target delegate information
public void LoadTargetDelegateInfo(Delegate del)
Parameters
del
Delegate
Run()
Runs the action.
public override void Run()
RunAsync()
Runs the worker as a new thread. For internal purposes only, use method Start instead.
[Obsolete("Method was not intended for public use and will be removed.")]
[ObsoleteSince(29, 3)]
public override void RunAsync()
Start(bool)
Starts the thread.
public void Start(bool sequence = false)
Parameters
sequence
boolIf true, the thread is a part of the sequence and should perform the actions after the previous thread finishes
Wrap(Action, bool)
Wraps the given method into CMSThread context
public static Action Wrap(Action action, bool multipleThreads = false)
Parameters
action
ActionAction to wrap
multipleThreads
boolIf true, the wrapped method may be used by multiple threads. Use this parameter to ensure that all the threads receive the original context values.
Returns
- Action
WrapFunc<TResult>(Func<TResult>, bool)
Wraps the given method into CMSThread context
public static Func<TResult> WrapFunc<TResult>(Func<TResult> action, bool multipleThreads = false)
Parameters
action
Func<TResult>Action to wrap
multipleThreads
boolIf true, the wrapped method may be used by multiple threads. Use this parameter to ensure that all the threads receive the original context values.
Returns
- Func<TResult>
Type Parameters
TResult
WrapFunc<T1, TResult>(Func<T1, TResult>, bool)
Wraps the given method into CMSThread context
public static Func<T1, TResult> WrapFunc<T1, TResult>(Func<T1, TResult> action, bool multipleThreads = false)
Parameters
action
Func<T1, TResult>Action to wrap
multipleThreads
boolIf true, the wrapped method may be used by multiple threads. Use this parameter to ensure that all the threads receive the original context values.
Returns
- Func<T1, TResult>
Type Parameters
T1
TResult
Wrap<T>(Action<T>, bool)
Wraps the given method into CMSThread context
public static Action<T> Wrap<T>(Action<T> action, bool multipleThreads = false)
Parameters
action
Action<T>Action to wrap
multipleThreads
boolIf true, the wrapped method may be used by multiple threads. Use this parameter to ensure that all the threads receive the original context values.
Returns
- Action<T>
Type Parameters
T
Wrap<T1, T2>(Action<T1, T2>, bool)
Wraps the given method into CMSThread context
public static Action<T1, T2> Wrap<T1, T2>(Action<T1, T2> action, bool multipleThreads = false)
Parameters
action
Action<T1, T2>Action to wrap
multipleThreads
boolIf true, the wrapped method may be used by multiple threads. Use this parameter to ensure that all the threads receive the original context values.
Returns
- Action<T1, T2>
Type Parameters
T1
T2