Represents a task, that can be executed in the IDispatcher thread
Namespace: Dapfor.Wpf.ThreadingAssembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)
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 | |
---|---|
//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(() => Console.WriteLine("Called in the anonymous method: object = {0}", data))); } else { Console.WriteLine("No synchronization required: object = {0}", data); } } |