Executes ITask objects with or without blocking the calling thread

Namespace: Dapfor.Wpf.Threading
Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)

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
public partial class SomeWindow : Window
{
    private readonly IDispatcher dispatcher;

    public SomeWindow()
    {
        InitializeComponent();

        this.dispatcher = new GuiDispatcher(this.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.Content = text;
            }));
        }
        else
        {
            //This is the GUI thread. 
            this.Content = text;
        }
    }
}

See Also