Class ThreadBase
- Namespace
- ArcanaDevelopment.adTempus.Shared
- Assembly
- ArcanaDevelopment.adTempus.Shared.dll
public abstract class ThreadBase
- Inheritance
-
objectThreadBase
Constructors
ThreadBase()
Creates a new thread.
protected ThreadBase()
Remarks
The Start method must be called to start the thread.
ThreadBase(string)
Creates a new thread with the specified name.
protected ThreadBase(string name)
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
Fields
thread
Holds the Thread object used to control the thread.
protected Thread thread
Field Value
- Thread
Properties
IsRunning
Indicates whether the thread is running.
public bool IsRunning { get; }
Property Value
- bool
ShouldTerminate
Indicates whether termination has been requested.
public bool ShouldTerminate { get; }
Property Value
- bool
TerminateEvent
Event that is set when termination is requested.
public WaitHandle TerminateEvent { get; }
Property Value
- WaitHandle
ThreadId
public int ThreadId { get; }
Property Value
- int
ThreadName
public string ThreadName { get; protected set; }
Property Value
- string
WakeEvent
The Event used by the Sleep method so that sleep can be interrupted by the Wake or Terminate methods.
protected AutoResetEvent WakeEvent { get; }
Property Value
- AutoResetEvent
Methods
~ThreadBase()
protected ~ThreadBase()
GetApartmentState()
public ApartmentState GetApartmentState()
Returns
- ApartmentState
RunThread()
Implemented by the derived class to do the work.
protected abstract void RunThread()
Remarks
The derived class should do all its work in RunThread. It must call ShouldTerminate frequently so it knows when it should terminate.
SetApartmentState(ApartmentState)
public void SetApartmentState(ApartmentState value)
Parameters
| Name | Type | Description |
|---|---|---|
value |
ApartmentState |
Sleep(int)
Suspends thread execution for the specified number of milliseconds, or until the thread is terminated or a wake signal is sent.
protected virtual ThreadBase.SleepResult Sleep(int timeout)
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
int |
Returns
- ThreadBase.SleepResult
A value indicating whether the timeout expired, or the thread was terminated or woken.
Sleep(int, out int, params WaitHandle[])
Waits for the specified handles plus the thread's Wake event handle.
protected ThreadBase.SleepResult Sleep(int timeoutMS, out int signalledEvent, params WaitHandle[] waitHandles)
Parameters
| Name | Type | Description |
|---|---|---|
timeoutMS |
int | |
signalledEvent |
int | The index of the waitHandle that was signalled, if the result is WaitHandleSignaled |
waitHandles |
WaitHandle[] |
Returns
Sleep(TimeSpan)
Suspends thread execution for the specified number of milliseconds, or until the thread is terminated or a wake signal is sent.
protected virtual ThreadBase.SleepResult Sleep(TimeSpan timeout)
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
TimeSpan |
Returns
- ThreadBase.SleepResult
A value indicating whether the timeout expired, or the thread was terminated or woken.
Start()
Starts the thread
public virtual void Start()
Remarks
Start creates a thread object pointed to ThreadProc, which calls RunThread.
Terminate(int, bool)
Instructs the thread to terminate and waits for the specified number of milliseconds for the thread to finish processing.
public virtual bool Terminate(int timeout, bool forceAbort)
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
int | The number of milliseconds to wait after requesting the termination and before returning. |
forceAbort |
bool | If True, the thread is aborted if it does not terminate itself within the specified timeout interval. |
Returns
- bool
True if the thread terminates within the specified time; False if the timeout elapses.
WaitForCompletion(int)
Waits for the specified number of milliseconds for the thread to execute.
public virtual bool WaitForCompletion(int timeout)
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
int | Number of milliseconds to wait. Specify System.Threading.Timeout.Infinite to wait forever. |
Returns
- bool
Returns True if the thread finished or False if the timeout elapsed.
Wake()
Signals the thread to wake if it is sleeping.
public virtual void Wake()
Events
ThreadFinished
public event ThreadBase.ThreadFinishedHandler ThreadFinished