private static void Run(FSimpleDelegate func, EAsyncThreadType threadType, bool waitForComplete) { switch (threadType) { case EAsyncThreadType.GameThreadUnloadIgnore: case EAsyncThreadType.GameThread: if (IsInGameThread()) { func(); return; } break; case EAsyncThreadType.RHIThread: if (IsInRHIThread()) { func(); return; } break; case EAsyncThreadType.RenderingThread: if (IsInRenderingThread()) { func(); return; } break; } if (HotReload.IsUnloading) { return; } AsyncCallback callback = new AsyncCallback(func, threadType); lock (callbacks) { callbacks.Add(callback); } Native_FAsync.AsyncTask(callback.Run, threadType); if (waitForComplete) { callback.WaitForComplete(); } else { callback.Dispose(); } }