static public void QuitWindowsEventLoop() { if (IsWindowsEventLoopQuitRequested) { return; } MainThreadSynchronizationContext.Send(delegate { if (IsWindowsEventLoopQuitRequested) { return; } IsWindowsEventLoopQuitRequested = true; #if SUPPORT_WPF if (LoopMode == EventLoopMode.WPF) { _wpfapp?.Shutdown(); } #endif if (LoopMode == EventLoopMode.LibCef) { LibCefInterop.cef_quit_message_loop(); } if (LoopMode == EventLoopMode.WinForms) { WF.Application.Exit(); //This is not a good solution, hang } }, null); }
public TestData(string testName, ILogging logger, string serverDirectory) { TestName = testName; Logger = logger; Watch = new Stopwatch(); TestPath = SPath.CreateTempDirectory(testName); TaskManager = new TaskManager(); try { TaskManager.Initialize(); } catch { // we're on the nunit sync context, which can't be used to create a task scheduler // so use a different context as the main thread. The test won't run on the main nunit thread ourContext = new MainThreadSynchronizationContext(TaskManager.Token); TaskManager.Initialize(ourContext); } Environment = new UnityEnvironment(testName); InitializeEnvironment(); ProcessManager = new ProcessManager(Environment); Configuration = new ServerConfiguration(serverDirectory); Logger.Trace($"START {testName}"); Watch.Start(); }
static public void InvokeInAppThread(Action handler) { if (handler == null) throw new ArgumentNullException(nameof(handler)); MainThreadSynchronizationContext.Send(delegate { handler(); }, null); }
static public void PostToAppThread(Action handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } MainThreadSynchronizationContext.Post(delegate { handler(); }, null); }
public ProcessServer(ITaskManager taskManager, IEnvironment environment, IRpcProcessConfiguration configuration) { Environment = environment; completionTask = completionHandle.ToTask(); ownsTaskManager = taskManager == null; if (ownsTaskManager) { taskManager = new TaskManager(); try { taskManager.Initialize(); } catch { ourContext = new MainThreadSynchronizationContext(cts.Token); taskManager.Initialize(ourContext); } } else { externalCts = CancellationTokenSource.CreateLinkedTokenSource(taskManager.Token); externalCts.Token.Register(Dispose); } TaskManager = taskManager; if (configuration == null) { configuration = new ApplicationConfigurationWrapper(TaskManager, ApplicationConfiguration.instance); // read the executable path up front so it gets serialized if it needs to, while we're on the main thread var _ = configuration.ExecutablePath; } if (string.IsNullOrEmpty(configuration.AccessToken)) { configuration.AccessToken = GenerateAccessToken(); } Configuration = configuration; localProcessManager = new ProcessManager(Environment); processManager = new RemoteProcessManager(this, localProcessManager.DefaultProcessEnvironment, cts.Token); notifications = new ServerNotifications(this); #if UNITY_EDITOR UnityEditor.EditorApplication.quitting += ShutdownSync; #endif }
private void Awake() { var currentContext = SynchronizationContext.Current; if (currentContext == null) { var context = new MainThreadSynchronizationContext(this); SynchronizationContext.SetSynchronizationContext(context); _context = context; _mainThreadContext = context; } else { _mainThreadContext = currentContext; } _actionQueue = new Queue <InvokeResult>(); }
private void Awake() { var currentContext = SynchronizationContext.Current; if (currentContext == null) { var context = new MainThreadSynchronizationContext(this); SynchronizationContext.SetSynchronizationContext(context); _context = context; _mainThreadContext = context; } else { _mainThreadContext = currentContext; } #if NET_2_0 || NET_2_0_SUBSET _actionQueue = new Queue <InvokeResult>(); #else _actionQueue = new ConcurrentQueue <InvokeResult>(); #endif }
public MainThread() { _disposableBag.Add(Stop); SynchronizationContext = new MainThreadSynchronizationContext(this); Thread.Start(this); }