Table of Contents

Class CMSThread

Namespace
CMS.Base
Assembly
CMS.Base.dll

Wrapper class for System.Threading.Thread object with additional log and context item possibilities.

public sealed class CMSThread : AbstractWorker
Inheritance
object
CMSThread
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 ThreadStart

Thread start method

CMSThread(ThreadStart, ThreadSettings)

Creates new instance of CMSThread.

public CMSThread(ThreadStart start, ThreadSettings settings)

Parameters

start ThreadStart

A System.Threading.ThreadStart delegate that represents the methods to be invoked when this thread begins executing.

settings ThreadSettings

Settings 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 ThreadStart

Thread start method

createLog bool

Indicates whether thread should create it's own log.

mode ThreadModeEnum

Thread 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

ILogContext

Mode

If true, the thread runs synchronously

public ThreadModeEnum Mode { get; }

Property Value

ThreadModeEnum

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

IPerformanceCounter

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 CMSThread

Thread 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 Guid

Thread GUID

Returns

CMSThread

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 bool

If 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 Action

Action to wrap

multipleThreads bool

If 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 bool

If 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 bool

If 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 bool

If 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 bool

If 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