Class WorkQueue
Represents a queue of work items to be completed by a thread.
Inherited Members
Namespace: SociallyDistant.Core.Core.Threading
Assembly: SociallyDistant.Framework.dll
Syntax
public class WorkQueue
Remarks
This class is designed for multi-threaded workloads. A programmer can create a work queue and give it to a thread that's meant to perform all work in the queue. Other threads can then enqueue work to be completed by the original thread's work queue.
Work is completed by the work queue in the order that it is enqueued, with the most-recent work item being completed last.
A work queue can also be used to allow background threads to execute work on the main thread, for example to access thread-unsafe Unity APIs.
Properties
Count
Gets the amount of items still left on the queue.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
MaximumWorkPerUpdate
Gets or sets how many work items in the queue can be executed by the work thread at once. If set to 0, there is no maximum amount of work and the thread will execute work items until the queue is empty.
Declaration
public int MaximumWorkPerUpdate { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
Enqueue(Action)
Adds a new work item to the queue.
Declaration
public void Enqueue(Action work)
Parameters
Type | Name | Description |
---|---|---|
Action | work | An action representing the work to be completed. |
EnqueueAsync(Action)
Adds a new work item to the queue and returns an awaitable task that completes when the work is completed.
Declaration
public Task EnqueueAsync(Action work)
Parameters
Type | Name | Description |
---|---|---|
Action | work | An action representing the work to be completed |
Returns
Type | Description |
---|---|
Task | A task that completes when the work item is executed. |
RunPendingWork()
Executes any pending work in the queue.
Declaration
public void RunPendingWork()