Unosquare
    Show / Hide Table of Contents

    Class WaitEventFactory

    Provides a Manual Reset Event factory with a unified API.

    Inheritance
    Object
    WaitEventFactory
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    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 true creates a slim version of the wait event.

    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.

    Comments

    Back to top Copyright © 2017-2019 Unosquare