static async UniTask FooBarAsync() { await using (UniTask.ReturnToCurrentSynchronizationContext()) { await UniTask.SwitchToThreadPool(); } }
async UniTaskVoid ReturnToMainThreadTest() { var d = UniTask.ReturnToCurrentSynchronizationContext(); try { UnityEngine.Debug.Log("In MainThread?" + Thread.CurrentThread.ManagedThreadId); UnityEngine.Debug.Log("SyncContext is null?" + (SynchronizationContext.Current == null)); await UniTask.SwitchToThreadPool(); UnityEngine.Debug.Log("In ThreadPool?" + Thread.CurrentThread.ManagedThreadId); UnityEngine.Debug.Log("SyncContext is null?" + (SynchronizationContext.Current == null)); } finally { await d.DisposeAsync(); } UnityEngine.Debug.Log("In ThreadPool?" + Thread.CurrentThread.ManagedThreadId); UnityEngine.Debug.Log("SyncContext is null2" + (SynchronizationContext.Current == null)); }