2using System.Collections.Generic;
4using System.Threading.Tasks;
55 private readonly ManualResetEvent terminate =
new ManualResetEvent(
false);
56 private readonly AutoResetEvent newTask =
new AutoResetEvent(
false);
57 private readonly LinkedList<ISyncTask> tasks =
new LinkedList<ISyncTask>();
58 private Thread thread;
59 private bool terminating =
false;
60 private bool terminated =
false;
61 private bool idle =
true;
62 private bool working =
false;
70 this.thread =
new Thread(this.Executor);
79 if (!this.terminating && !this.terminated)
81 this.terminating =
true;
82 this.terminate?.Set();
99 public bool Idle => this.idle;
108 if (this.terminating || this.terminated)
109 throw new InvalidOperationException(
"Thread executer is being terminated or has been terminated.");
113 this.tasks.AddLast(Task);
161 Callback, Arg1, Arg2);
188 private void Executor()
192 WaitHandle[] Handles =
new WaitHandle[] { this.newTask, this.terminate };
194 bool Continue =
true;
198 switch (WaitHandle.WaitAny(Handles, 1000))
205 if (this.tasks.First is
null)
209 ToExecute = this.tasks.First.Value;
210 this.tasks.RemoveFirst();
214 if (!(ToExecute is
null))
226 while (!(ToExecute is
null));
241 this.terminating =
false;
242 this.terminated =
true;
244 this.working =
false;
247 this.terminate.Dispose();
248 this.newTask.Dispose();
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Task with zero arguments to be synchronized.
Task< ReturnType > WaitAsync()
Waits for the task to complete.
Task with one argument to be synchronized.
Task< ReturnType > WaitAsync()
Waits for the task to complete.
Task with one argument to be synchronized.
Task< ReturnType > WaitAsync()
Waits for the task to complete.
Task with one argument to be synchronized.
Task< ReturnType > WaitAsync()
Waits for the task to complete.
Class that executes tasks from the same the same thread, and that provides an asynchronous interface ...
bool Terminating
If execution thread is terminating.
Task< ReturnType > Execute< ReturnType, Arg1Type, Arg2Type >(Callback2< ReturnType, Arg1Type, Arg2Type > Callback, Arg1Type Arg1, Arg2Type Arg2)
Executes a task with one argument.
bool Working
If thread is working.
Task< ReturnType > Execute< ReturnType >(Callback0< ReturnType > Callback)
Executes a task with no arguments.
ThreadExecutor()
Class that executes tasks from the same the same thread, and that provides an asynchronous interface ...
bool Terminated
If execution thread has terminated.
bool Idle
If thread is idle
Task< ReturnType > Execute< ReturnType, Arg1Type >(Callback1< ReturnType, Arg1Type > Callback, Arg1Type Arg1)
Executes a task with one argument.
Task< ReturnType > Execute< ReturnType, Arg1Type, Arg2Type, Arg3Type >(Callback3< ReturnType, Arg1Type, Arg2Type, Arg3Type > Callback, Arg1Type Arg1, Arg2Type Arg2, Arg3Type Arg3)
Executes a task with one argument.
void Dispose()
Disposes of the object and terminates the thread executor.
Interface for tasks to be synckronized.
delegate ReturnType Callback3< ReturnType, Arg1Type, Arg2Type, Arg3Type >(Arg1Type Arg1, Arg2Type Arg2, Arg3Type Arg3)
Delegate to methods of three parameters and a given return type.
delegate ReturnType Callback1< ReturnType, Arg1Type >(Arg1Type Arg1)
Delegate to methods of one parameter and a given return type.
delegate ReturnType Callback0< ReturnType >()
Delegate to methods of zero parameters and a given return type.
delegate ReturnType Callback2< ReturnType, Arg1Type, Arg2Type >(Arg1Type Arg1, Arg2Type Arg2)
Delegate to methods of two parameters and a given return type.