Executes tasks in GUI thread.
Namespace: Dapfor.Net.ThreadingAssembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)
Syntax
C# |
---|
public sealed class GuiDispatcher : Control, IDispatcher |
Visual Basic |
---|
Public NotInheritable Class GuiDispatcher Inherits Control Implements IDispatcher |
Visual C++ |
---|
public ref class GuiDispatcher sealed : public Control, IDispatcher |
F# |
---|
[<SealedAttribute>] type GuiDispatcher = class inherit Control interface IDispatcher end |
Remarks
Following example demonstrates how to use dispatcher:
Copy | |
---|---|
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; } } } |
Inheritance Hierarchy
System..::..Object
System..::..MarshalByRefObject
System.ComponentModel..::..Component
System.Windows.Forms..::..Control
Dapfor.Net.Threading..::..GuiDispatcher
System..::..MarshalByRefObject
System.ComponentModel..::..Component
System.Windows.Forms..::..Control
Dapfor.Net.Threading..::..GuiDispatcher