Class WaitEventFactory
Provides a Manual Reset Event factory with a unified API.
Inherited Members
Namespace: Swan.Threading
Syntax
public static class WaitEventFactory
Examples
The following example shows how to use the WaitEventFactory class.
using Swan.Threading;
public class Example
{
// create a WaitEvent using the slim version
private static readonly IWaitEvent waitEvent = WaitEventFactory.CreateSlim(false);
public static void Main()
{
Task.Factory.StartNew(() =>
{
DoWork(1);
});
Task.Factory.StartNew(() =>
{
DoWork(2);
});
// send first signal
waitEvent.Complete();
waitEvent.Begin();
Thread.Sleep(TimeSpan.FromSeconds(2));
// send second signal
waitEvent.Complete();
Terminal.Readline();
}
public static void DoWork(int taskNumber)
{
$"Data retrieved:{taskNumber}".WriteLine();
waitEvent.Wait();
Thread.Sleep(TimeSpan.FromSeconds(2));
$"All finished up {taskNumber}".WriteLine();
}
}
Methods
Create(Boolean)
Creates a Wait Event backed by a standard ManualResetEvent.
Declaration
public static IWaitEvent Create(bool isCompleted)
Parameters
Type | Name | Description |
---|---|---|
Boolean | isCompleted | if initially set to completed. Generally true. |
Returns
Type | Description |
---|---|
IWaitEvent | The Wait Event. |
Create(Boolean, Boolean)
Creates a Wait Event backed by a ManualResetEventSlim.
Declaration
public static IWaitEvent Create(bool isCompleted, bool useSlim)
Parameters
Type | Name | Description |
---|---|---|
Boolean | isCompleted | if initially set to completed. Generally true. |
Boolean | useSlim | if set to |
Returns
Type | Description |
---|---|
IWaitEvent | The Wait Event. |
CreateSlim(Boolean)
Creates a Wait Event backed by a ManualResetEventSlim.
Declaration
public static IWaitEvent CreateSlim(bool isCompleted)
Parameters
Type | Name | Description |
---|---|---|
Boolean | isCompleted | if initially set to completed. Generally true. |
Returns
Type | Description |
---|---|
IWaitEvent | The Wait Event. |