Executes ITask objects with or without blocking the calling thread

Namespace: Dapfor.Net.Threading
Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)

Syntax

C#
public interface IDispatcher
Visual Basic
Public Interface IDispatcher
Visual C++
public interface class IDispatcher
F#
type IDispatcher =  interface end

Remarks

Following example demonstrates how to use dispatcher:
 Copy imageCopy
void Initialize()
{
    //Create a GUI dispatcher
    IDispatcher dispatcher = new GuiDispatcher();

    //The control will use dispatcher to synchronize threads
    SomeControl control = new SomeControl(dispatcher);
}

class SomeControl : UserControl
{
    private readonly IDispatcher dispatcher;

    public SomeControl(IDispatcher dispatcher)
    {
        this.dispatcher = dispatcher;
    }

    //This method can be called from non-GUI thread
    private void DrawTextInControl(string text)
    {
        if (dispatcher.SynchronizationRequired)
        {
            //Create a task that will be executed in dispatcher thread without blocking the calling thread
            dispatcher.Dispatch(new DelegateTask(delegate
            {
                this.Text = text;
            }));
        }
        else
        {
            //This is the GUI thread. 
            this.Text = text;
        }
    }
}

See Also