Represents a task, that can be executed in the IDispatcher 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 ITask
Visual Basic
Public Interface ITask
Visual C++
public interface class ITask
F#
type ITask =  interface end

Remarks

Following example demonstrates how to use tasks:
 Copy imageCopy
//Synchronization code
private void ExplicitSynchronizationCall(object data)
{
    if(dispatcher.SynchronizationRequired)
    {
        //Create a task that will be executed in dispatcher thread without blocking the calling thread
        dispatcher.Dispatch(new SynchronizationTask(data));
    }
    else
    {
        Console.WriteLine("No synchronization required: object = {0}", data);
    }
}

//Task implementstion
private class SynchronizationTask : ITask
{
    private readonly object data;
    public SynchronizationTask(object data)
    {
        this.data = data;
    }

    public void Execute()
    {
        Console.WriteLine("Called in the expliceit task: object = {0}", data);
    }
}


//The same example with anonymous methods. 
private void ImplicitSynchronizationCall(object data)
{
    if (dispatcher.SynchronizationRequired)
    {
        //Create a task that will be executed in dispatcher thread without blocking the calling thread
        dispatcher.Dispatch(new DelegateTask(delegate
        {
            Console.WriteLine("Called in the anonymous method: object = {0}", data);
        }));
    }
    else
    {
        Console.WriteLine("No synchronization required: object = {0}", data);
    }
}

See Also