Class AsyncFormWrapper<T>
Lazily starts a separate thread with a message loop for a System.Windows.Forms.Form.
public sealed class AsyncFormWrapper<T> where T : Form
Type Parameters
TThe type of the form to wrap.
- Inheritance
-
objectAsyncFormWrapper<T>
- Extension Methods
Constructors
AsyncFormWrapper(Func<T>)
Creates a new asynchronous form wrapper.
public AsyncFormWrapper(Func<T> init)
Parameters
initFunc<T>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.
public void Close()
Remarks
Does nothing if the System.Windows.Forms.Form was not yet created.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
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.
public void Post(Action<T> action)
Parameters
actionAction<T>The action to execute; gets passed the
Tinstance.
Exceptions
- 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.
public TResult Post<TResult>(Func<T, TResult> action)
Parameters
actionFunc<T, TResult>A delegate that is passed the System.Windows.Forms.Form instance and returns a result.
Returns
- TResult
The result returned by
action.
Type Parameters
TResultThe type of the result returned by
action.
Exceptions
- 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.
public void Send(Action<T> action)
Parameters
actionAction<T>The action to execute; gets passed the
Tinstance.
Exceptions
- OperationCanceledException
The form was closed.
SendLow(Action<T>)
Executes an action on the message loop thread without waiting for it to complete.
public void SendLow(Action<T> action)
Parameters
actionAction<T>The action to execute; gets passed the
Tinstance.
Remarks
Does nothing if the System.Windows.Forms.Form was not yet created.