NanoByte.Common
Static Public Member Functions | List of all members
NanoByte.Common.ThreadUtils Class Reference

Provides helper methods for launching Threads. More...

Static Public Member Functions

static Thread StartAsync ([NotNull] ThreadStart execute, [CanBeNull, Localizable(false)] string name=null)
 Starts executing a delegate in a new thread suitable for WinForms. More...
 
static Thread StartBackground ([NotNull] ThreadStart execute, [CanBeNull, Localizable(false)] string name=null)
 Starts executing a delegate in a new background thread (automatically terminated when application exits). More...
 
static void RunSta ([NotNull, InstantHandle] Action execute)
 Executes a delegate in a new ApartmentState.STA thread. Blocks the caller until the execution completes. More...
 
static T RunSta< T > ([NotNull, InstantHandle] Func< T > execute)
 Executes a delegate in a new ApartmentState.STA thread. Blocks the caller until the execution completes. More...
 

Detailed Description

Provides helper methods for launching Threads.

Member Function Documentation

◆ RunSta()

static void NanoByte.Common.ThreadUtils.RunSta ( [NotNull, InstantHandle] Action  execute)
inlinestatic

Executes a delegate in a new ApartmentState.STA thread. Blocks the caller until the execution completes.

Parameters
executeThe delegate to execute.

This is useful for code that needs to be executed in a Single-Threaded Apartment (e.g. WinForms code) when the calling thread is not set up to handle COM.

◆ RunSta< T >()

static T NanoByte.Common.ThreadUtils.RunSta< T > ( [NotNull, InstantHandle] Func< T >  execute)
inlinestatic

Executes a delegate in a new ApartmentState.STA thread. Blocks the caller until the execution completes.

Template Parameters
TThe type of the return value of execute .
Parameters
executeThe delegate to execute.
Returns
The return value of execute

This is useful for code that needs to be executed in a Single-Threaded Apartment (e.g. WinForms code) when the calling thread is not set up to handle COM.

◆ StartAsync()

static Thread NanoByte.Common.ThreadUtils.StartAsync ( [NotNull] ThreadStart  execute,
[CanBeNull, Localizable(false)] string  name = null 
)
inlinestatic

Starts executing a delegate in a new thread suitable for WinForms.

Parameters
executeThe delegate to execute.
nameA short name for the new thread; can be null.
Returns
The newly launched thread.

◆ StartBackground()

static Thread NanoByte.Common.ThreadUtils.StartBackground ( [NotNull] ThreadStart  execute,
[CanBeNull, Localizable(false)] string  name = null 
)
inlinestatic

Starts executing a delegate in a new background thread (automatically terminated when application exits).

Parameters
executeThe delegate to execute.
nameA short name for the new thread; can be null.
Returns
The newly launched thread.

The documentation for this class was generated from the following file: