Table of Contents

Class AsyncFormWrapper<T>

Namespace
NanoByte.Common.Threading
Assembly
NanoByte.Common.WinForms.dll

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

T

The type of the form to wrap.

Inheritance
object
AsyncFormWrapper<T>
Extension Methods

Constructors

AsyncFormWrapper(Func<T>)

Creates a new asynchronous form wrapper.

public AsyncFormWrapper(Func<T> init)

Parameters

init Func<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

action Action<T>

The action to execute; gets passed the T instance.

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

action Func<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

TResult

The 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

action Action<T>

The action to execute; gets passed the T instance.

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

action Action<T>

The action to execute; gets passed the T instance.

Remarks

Does nothing if the System.Windows.Forms.Form was not yet created.