Class MainThread
Allows calls onto the main thread from any other thread. This can be necessary, because the Unity API is only accessible from the main thread for the most part.
Inheritance
Inherited Members
Namespace: InsaneScatterbrain.Threading
Syntax
public static class MainThread
Properties
CommandHandler
The command handler that's used to handle any commands given.
Declaration
public static IMainThreadCommandHandler CommandHandler { get; set; }
Property Value
Type | Description |
---|---|
IMainThreadCommandHandler |
CoroutineCommandHandler
Declaration
public static IMainThreadCoroutineCommandHandler CoroutineCommandHandler { get; set; }
Property Value
Type | Description |
---|---|
IMainThreadCoroutineCommandHandler |
IsCurrent
Declaration
public static bool IsCurrent { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Cancel()
Stops executing any commands that might be running as soon as possible.
Declaration
public static void Cancel()
Execute(IMainThreadCommand, bool)
Executes the given action on the main thread.
Declaration
public static void Execute(IMainThreadCommand command, bool waitForCompletion = true)
Parameters
Type | Name | Description |
---|---|---|
IMainThreadCommand | command | The command to execute on the main thread. |
bool | waitForCompletion | Whether or not the calling thread should wait for completion of this command before continuing code execution. |
Execute(IMainThreadCoroutineCommand, bool)
Declaration
public static void Execute(IMainThreadCoroutineCommand command, bool waitForCompletion = true)
Parameters
Type | Name | Description |
---|---|---|
IMainThreadCoroutineCommand | command | |
bool | waitForCompletion |
Execute(Action, bool)
Executes the given action on the main thread.
Declaration
[Obsolete("This overload will likely be removed in 2.0.")]
public static void Execute(Action action, bool waitForCompletion = true)
Parameters
Type | Name | Description |
---|---|---|
System.Action | action | The action to execute on the main thread. |
bool | waitForCompletion | Whether or not the calling thread should wait for completion of this command before continuing code execution. |
Initialize()
This is called on load (either in the editor or in a build) from the main thread, so that a reference to the main thread is stored to execute commands on.
Declaration
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
Update()
Handles the execution for queued commands.
Declaration
public static void Update()
UpdateCoroutine()
Handles the execution for queued coroutine commands.
Declaration
public static IEnumerator UpdateCoroutine()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |