A dispatcher compatible with the ActorThreadingModel threading model, with a message queue based on a ConcurrentQueue.
The queue itself is processed from the ThreadPool.
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
public class ActorDispatcher : IActorDispatcher, IDispatcherRemarks
This implementation will append every action (as a result of the BeginInvoke(SendOrPostCallback, object) method) into a
ConcurrentQueue. It will then create a work item to process the ConcurrentQueue and schedule the work item to the ThreadPool.
The same work item keeps running until the message queue is empty, and then terminates.
You can use a different scheduling mechanism instead of the ThreadPool by deriving the class and overriding the ScheduleProcessQueue() method.
Note that the Invoke(SendOrPostCallback, object) method of the IDispatcher interface is not supported, because the ActorThreadingModel does not support synchronous calls.
Constructors
| Name | Description |
|---|---|
| ActorDispatcher() | Initializes a new instance of the ActorDispatcher class. |
Properties
| Name | Description |
|---|---|
| IsQueueEmpty | Gets a value indicating whether the queue is empty. |
Methods
| Name | Description |
|---|---|
| BeginInvoke(SendOrPostCallback, object) | Queues an action for asynchronous execution. |
| CheckAccess() | Determines whether the current thread has access to the current dispatcher. |
| Invoke(SendOrPostCallback, object) | Executes an action synchronously. |
| MustYield(int) | Determines whether the ProcessQueue() method should interrupt the processing of the message queue before the queue is empty. |
| OnQueueEmpty() | Method invoked when the queue becomes empty. The default implementation does not do anything. |
| ProcessQueue() | Processes the message queue synchronously. |
| ScheduleProcessQueue() | Schedules the execution of the ProcessQueue() method, typically on a worker thread or in the ThreadPool. The default implementation uses the ThreadPool on platforms that have a thread pool, otherwise it schedules a new Task. |