Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConsoleWorker.cs
1using System.Threading.Tasks;
2using Waher.Events;
4
6{
10 public static class ConsoleWorker
11 {
12 private static AsyncProcessor<WorkItem> worker = new AsyncProcessor<WorkItem>(1, "Console Output");
13
14 static ConsoleWorker()
15 {
16 Log.Terminating += Log_Terminating;
17 }
18
19 private static async Task Log_Terminating(object Sender, System.EventArgs e)
20 {
21 await Terminate();
22 Log.Terminating -= Log_Terminating;
23 }
24
25 internal static async Task Terminate()
26 {
27 if (!(worker is null))
28 {
29 await worker.DisposeAsync();
30 worker = null;
31 }
32 }
33
39 public static Task<bool> Forward(WorkItem Work)
40 {
41 return worker?.Forward(Work) ?? Task.FromResult(false);
42 }
43
47 public static bool Terminating => worker?.Terminating ?? true;
48
52 public static bool Terminated => worker?.Terminated ?? true;
53 }
54}
Processes console tasks, such as input and output, in a serialized asynchronous manner.
static bool Terminated
If the console worker has been terminated.
static Task< bool > Forward(WorkItem Work)
Forwards a work item for processing.
static bool Terminating
If the console worker is being terminated.
Processes work tasks, in an asynchronous manner.
bool Terminating
If the console worker is being terminated.
bool Terminated
If the console worker has been terminated.
async Task DisposeAsync()
Stops processing tasks and disposes the queue.
Task< bool > Forward(T Work)
Forwards a work item for processing.
Represents an asynchronous operation to be performed.
Definition: WorkItem.cs:10