diff Implab.Diagnostics.Interactive/InteractiveListener.cs @ 215:fe5101083150 v2

Fixed InteractiveListener to support OLE and clipboard. Safe.Dispose methods made more convinent
author cin
date Fri, 21 Apr 2017 14:27:17 +0300
parents 9c32ef39b851
children eedf4d834e67
line wrap: on
line diff
--- a/Implab.Diagnostics.Interactive/InteractiveListener.cs	Fri Apr 14 15:57:23 2017 +0300
+++ b/Implab.Diagnostics.Interactive/InteractiveListener.cs	Fri Apr 21 14:27:17 2017 +0300
@@ -17,7 +17,6 @@
         readonly Promise m_guiStarted = new Promise();
         
         readonly IPromise m_guiFinished;
-        //        readonly IPromise m_workerFinished = new Promise<object>();
         
         readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>();
         readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false);
@@ -30,8 +29,8 @@
         readonly ManualResetEvent m_pauseEvent = new ManualResetEvent(true);
 
         public InteractiveListener() {
-            m_guiFinished = AsyncPool.RunThread(GuiThread);
-            /*m_workerFinished = */AsyncPool.RunThread(QueueThread);
+            m_guiFinished = RunGuiThread();
+            AsyncPool.RunThread(QueueThread);
 
             m_guiStarted.Join();
         }
@@ -63,6 +62,31 @@
             }
         }
 
+        public IPromise RunGuiThread() {
+            var p = new Promise();
+
+            var caller = TraceContext.Instance.CurrentOperation;
+
+            var worker = new Thread(() => {
+                TraceContext.Instance.EnterLogicalOperation(caller, false);
+                try {
+                    Application.OleRequired();
+                    GuiThread();
+                    p.Resolve();
+                } catch (Exception e) {
+                    p.Reject(e);
+                } finally {
+                    TraceContext.Instance.Leave();
+                }
+            });
+            worker.SetApartmentState(ApartmentState.STA);
+            worker.IsBackground = true;
+            worker.Name = string.Format("{0} GUI Thread", nameof(InteractiveListener));
+            worker.Start();
+
+            return p;
+        }
+
         public void Pause() {
             // for consistency we need to set this properties atomically
             lock (m_pauseLock) {