public void DispatchMainThread(Action task) { if (Thread.CurrentThread.Name == null) { throw new System.Exception("iSCDRuntime: Already in main thread"); } Monitor.Enter(registeredTasks); iSCDThreadContainer container = ContainerForID(int.Parse(Thread.CurrentThread.Name)); Monitor.Enter(container); Action callback = () => { container.Resume(); //iSCDTools.LogVerbose("ISCD Runtime : " + iSCDTools.FormatThreadName(container) + " dispatched back from main thread."); }; TaskInformationPackage package = new TaskInformationPackage(task, callback, container.iSCD_RuntimeID); registeredTasks.Add(package); Monitor.Exit(registeredTasks); //iSCDTools.LogVerbose("ISCD Runtime : " + iSCDTools.FormatThreadName(container) + " ready to dispatch to main thread."); container.Pause(); container.WaitForResetEvent(); Monitor.Exit(container); if (IsDebugging()) { debugger.CountMainThreadDispatchs(); } }
public void PauseThread(int threadRuntimeID) { iSCDThreadContainer c = ContainerForID(threadRuntimeID); c.Pause(); if (Thread.CurrentThread.Name != null && int.Parse(Thread.CurrentThread.Name) == threadRuntimeID) { c.WaitForResetEvent(); } }