Class CMSThread
Wrapper class for System.Threading.Thread object with additional log and context item possibilities.
public sealed class CMSThread
- Inheritance
-
objectCMSThread
- 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
startThreadStartThread start method
CMSThread(ThreadStart, ThreadSettings)
Creates new instance of CMSThread.
public CMSThread(ThreadStart start, ThreadSettings settings)
Parameters
startThreadStartA System.Threading.ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
settingsThreadSettingsSettings object with required behavior of CMSThread object. The
settingsobject must not be modified.
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
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
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
threadCMSThreadThread for which to allow the empty context. Pass null for current thread.
GetCurrentThreadId()
Gets the current thread ID
public static int GetCurrentThreadId()
Returns
- int
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
delDelegate
Run()
Runs the action.
public void Run()
Start(bool)
Starts the thread.
public void Start(bool sequence = false)
Parameters
sequenceboolIf 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
actionActionAction to wrap
multipleThreadsboolIf 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
actionFunc<TResult>Action to wrap
multipleThreadsboolIf 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
actionFunc<T1, TResult>Action to wrap
multipleThreadsboolIf 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
T1TResult
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
actionAction<T>Action to wrap
multipleThreadsboolIf 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
actionAction<T1, T2>Action to wrap
multipleThreadsboolIf 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
T1T2
Events
OnStop
Raised when worker finishes.
public event EventHandler OnStop
Event Type
- EventHandler