BackgroundThreadAwaitable Awaitable object that completes when switching to a background thread.
Resumes execution on a ThreadPool background thread. Completes immediately when called from a background thread.
private async Awaitable<float> DoSomeHeavyComputationInBackgroundAsync(bool continueOnMainThread = true) { await Awaitable.BackgroundThreadAsync(); // do some heavy math here float result = 42;
// by default, switch back to main thread: if(continueOnMainThread){ await Awaitable.MainThreadAsync(); } return result; }
public async Awaitable Start() { var computationResult = await DoSomeHeavyComputationInBackgroundAsync(); await SceneManager.LoadSceneAsync("my-scene"); }