diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2021-09-10 11:41:26 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2021-09-10 11:41:26 +0300 |
commit | 2bcb4e79c26a46dde235b78de0f5dd2b95d68d99 (patch) | |
tree | 3f9e72a6bd5c728f9ab2b5ed293717169d9649d6 | |
parent | 9167376c05961733f7cf7fca66ff4c8dac871f1c (diff) |
Revert "HACK: Add support for a console main loop"dev/lluis/revert-hack
This reverts commit d0821012bf30ce2771d1bc878a34f6bd555b00ba.
-rw-r--r-- | src/framework/GuiUnit/TestRunner.cs | 1 | ||||
-rw-r--r-- | src/framework/GuiUnit/XwtMainLoopIntegration.cs | 117 |
2 files changed, 0 insertions, 118 deletions
diff --git a/src/framework/GuiUnit/TestRunner.cs b/src/framework/GuiUnit/TestRunner.cs index 4ffd57b..e7acccf 100644 --- a/src/framework/GuiUnit/TestRunner.cs +++ b/src/framework/GuiUnit/TestRunner.cs @@ -59,7 +59,6 @@ namespace GuiUnit try { mainLoop = mainLoop ?? new XwtMainLoopIntegration (); } catch { } try { mainLoop = mainLoop ?? new MonoMacMainLoopIntegration (); } catch { } try { mainLoop = mainLoop ?? new GtkMainLoopIntegration (); } catch { } - mainLoop = mainLoop ?? new ConsoleMainLoop (); return mainLoop; } set { mainLoop = value; diff --git a/src/framework/GuiUnit/XwtMainLoopIntegration.cs b/src/framework/GuiUnit/XwtMainLoopIntegration.cs index 485cdfb..ff6d598 100644 --- a/src/framework/GuiUnit/XwtMainLoopIntegration.cs +++ b/src/framework/GuiUnit/XwtMainLoopIntegration.cs @@ -76,122 +76,5 @@ namespace GuiUnit Application.GetMethod("Exit").Invoke(null, null); } } - - class ConsoleMainLoop : System.Threading.SynchronizationContext, IMainLoopIntegration - { - System.Collections.Generic.Queue<InvokerHelper> work = - new System.Collections.Generic.Queue<InvokerHelper>(); - - System.Collections.Generic.Queue<Tuple<System.Threading.SendOrPostCallback, object>> contextWork = - new System.Collections.Generic.Queue<Tuple<System.Threading.SendOrPostCallback, object>>(); - - bool endLoop; - - public void InitializeToolkit() - { - var runtime = Type.GetType("MonoDevelop.Core.Runtime, MonoDevelop.Core"); - if (runtime == null) - return; - - var property = runtime.GetProperty ("MainSynchronizationContext", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); - if (property == null) - return; - - System.Threading.SynchronizationContext.SetSynchronizationContext(this); - property.SetValue (null, System.Threading.SynchronizationContext.Current); - } - - public void InvokeOnMainLoop (InvokerHelper helper) - { - lock (work) - { - work.Enqueue (helper); - System.Threading.Monitor.Pulse (work); - } - } - - public void RunMainLoop () - { - do - { - InvokerHelper next = null; - Tuple<System.Threading.SendOrPostCallback, object> nextContext = null; - lock (work) - { - if (work.Count > 0 && !endLoop) - next = work.Dequeue (); - else if (contextWork.Count > 0 && !endLoop) - nextContext = contextWork.Dequeue (); - else if (!endLoop) - System.Threading.Monitor.Wait (work); - } - if (next != null) - { - try - { - next.Invoke (); - } - catch (Exception ex) - { - Console.WriteLine (ex); - } - } - if (nextContext != null) - { - try - { - nextContext.Item1(nextContext.Item2); - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - } - } while (!endLoop); - } - - public void Shutdown () - { - lock (work) - { - endLoop = true; - System.Threading.Monitor.Pulse (work); - } - } - - public override void Post (System.Threading.SendOrPostCallback d, object state) - { - lock (work) - { - contextWork.Enqueue (new Tuple<System.Threading.SendOrPostCallback, object>(d, state)); - System.Threading.Monitor.Pulse (work); - } - } - - public override void Send (System.Threading.SendOrPostCallback d, object state) - { - var evt = new System.Threading.ManualResetEventSlim (false); - Exception exception = null; - Post (s => - { - try - { - d.Invoke (state); - } - catch (Exception ex) - { - exception = ex; - } - finally - { - System.Threading.Thread.MemoryBarrier (); - evt.Set (); - } - }, null); - evt.Wait (); - if (exception != null) - throw exception; - } - } } |