Class AsyncFormWrapper<T>
Lazily starts a separate thread with a message loop for a System.Windows.Forms.Form.
Namespace: NanoByte.Common.Threading
Assembly: NanoByte.Common.WinForms.dll
Syntax
public sealed class AsyncFormWrapper<T> : Object where T : Form
Type Parameters
Name | Description |
---|---|
T | The type of the form to wrap. |
Constructors
AsyncFormWrapper(Func<T>)
Creates a new asynchronous form wrapper.
Declaration
public AsyncFormWrapper(Func<T> init)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | init | Callback that creates an instance of the form for the message loop. |
Methods
Close()
Closes the System.Windows.Forms.Form and stops the message loop.
Declaration
public void Close()
Remarks
Does nothing if the System.Windows.Forms.Form was not yet created.
Dispose()
Declaration
public void Dispose()
Post(Action<T>)
Starts the message loop if it is not running yet and executes an action on its thread waiting for it to complete.
Declaration
public void Post(Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to execute; gets passed the |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | The form was closed. |
Post<TResult>(Func<T, TResult>)
Starts the message loop if it is not running yet and executes an action on its thread waiting for it to complete.
Declaration
public TResult Post<TResult>(Func<T, TResult> action)
Parameters
Type | Name | Description |
---|---|---|
Func<T, TResult> | action | A delegate that is passed the System.Windows.Forms.Form instance and returns a result. |
Returns
Type | Description |
---|---|
TResult | The result returned by |
Type Parameters
Name | Description |
---|---|
TResult | The type of the result returned by |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | The form was closed. |
Send(Action<T>)
Starts the message loop if it is not running yet and executes an action on its thread without waiting for it to complete.
Declaration
public void Send(Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to execute; gets passed the |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | The form was closed. |
SendLow(Action<T>)
Executes an action on the message loop thread without waiting for it to complete.
Declaration
public void SendLow(Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to execute; gets passed the |
Remarks
Does nothing if the System.Windows.Forms.Form was not yet created.