Class QueuedActionThread
This class is intended to be the base class for other classes that need to queue actions and execute them within the context of a single long-running Thread. It is generally not used directly in a stand-alone manner.
After constructing a class derived from this class, the derived class must call the Start() method to start the background task. When the derived class is shutting down, it must call the Shutdown() method.
Actions are queued for execution by calling the EnqueueAction() method.
Derived classes can override the DoTimedEvents() methods so that they can do work periodically within the tread context of this class. The DoTimedEvents() method is called each time through the task loop. The maximum period of execution is the WaitIntervalMsec value provided in the constructor.
Inherited Members
Namespace: SipLib.Threading
Assembly: SipLib.dll
Syntax
public class QueuedActionThread
Constructors
| Edit this page View SourceQueuedActionThread(ThreadPriority, int)
Constructor.
Declaration
public QueuedActionThread(ThreadPriority Priority = ThreadPriority.Normal, int WaitIntervalMsec = 100)
Parameters
Type | Name | Description |
---|---|---|
ThreadPriority | Priority | Specifies the thread priority. Optional. The default is Normal |
int | WaitIntervalMsec | Specifies the maximum number of milliseconds that the worker thread spends sleeping. Optional. The default value is 100 milliseconds. The minimum value is 0 msec. There is no maximum value. |
Methods
| Edit this page View SourceDoTimedEvents()
This method is called from within the thread context of the worker thread managed by this class. The base class implementation performs no work. This method must be overridden by the derived class if periodic actions are required.
The method is called once for each iteration of the thread's main loop. The maximum period between calls is specified by the WaitIntervalMsec constructor parameter.
Declaration
protected virtual void DoTimedEvents()
EnqueueWork(Action)
Enqueues an action and signals the background worker thread to wake up and dequeue actions from the internal action queue and perform them.
Declaration
public void EnqueueWork(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | Action to be queued and executed. |
Shutdown()
Causes the background thread that executes actions to terminate. The background worker task may terminate until the action that is currently being executed completes or a maximum of 500 ms elapses.
Declaration
public void Shutdown()
Start()
Starts the thread that executes queued actions.
Declaration
public void Start()