comparison 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
comparison
equal deleted inserted replaced
214:9c32ef39b851 215:fe5101083150
15 15
16 SynchronizationContext m_syncGuiThread; 16 SynchronizationContext m_syncGuiThread;
17 readonly Promise m_guiStarted = new Promise(); 17 readonly Promise m_guiStarted = new Promise();
18 18
19 readonly IPromise m_guiFinished; 19 readonly IPromise m_guiFinished;
20 // readonly IPromise m_workerFinished = new Promise<object>();
21 20
22 readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>(); 21 readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>();
23 readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); 22 readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false);
24 23
25 int m_queueLength; 24 int m_queueLength;
28 readonly object m_pauseLock = new object(); 27 readonly object m_pauseLock = new object();
29 bool m_paused; 28 bool m_paused;
30 readonly ManualResetEvent m_pauseEvent = new ManualResetEvent(true); 29 readonly ManualResetEvent m_pauseEvent = new ManualResetEvent(true);
31 30
32 public InteractiveListener() { 31 public InteractiveListener() {
33 m_guiFinished = AsyncPool.RunThread(GuiThread); 32 m_guiFinished = RunGuiThread();
34 /*m_workerFinished = */AsyncPool.RunThread(QueueThread); 33 AsyncPool.RunThread(QueueThread);
35 34
36 m_guiStarted.Join(); 35 m_guiStarted.Join();
37 } 36 }
38 37
39 void GuiThread() { 38 void GuiThread() {
59 m_syncGuiThread.Post(x => m_form.AddTraceEvent(item),null); 58 m_syncGuiThread.Post(x => m_form.AddTraceEvent(item),null);
60 } else { 59 } else {
61 m_queueEvent.WaitOne(); 60 m_queueEvent.WaitOne();
62 } 61 }
63 } 62 }
63 }
64
65 public IPromise RunGuiThread() {
66 var p = new Promise();
67
68 var caller = TraceContext.Instance.CurrentOperation;
69
70 var worker = new Thread(() => {
71 TraceContext.Instance.EnterLogicalOperation(caller, false);
72 try {
73 Application.OleRequired();
74 GuiThread();
75 p.Resolve();
76 } catch (Exception e) {
77 p.Reject(e);
78 } finally {
79 TraceContext.Instance.Leave();
80 }
81 });
82 worker.SetApartmentState(ApartmentState.STA);
83 worker.IsBackground = true;
84 worker.Name = string.Format("{0} GUI Thread", nameof(InteractiveListener));
85 worker.Start();
86
87 return p;
64 } 88 }
65 89
66 public void Pause() { 90 public void Pause() {
67 // for consistency we need to set this properties atomically 91 // for consistency we need to set this properties atomically
68 lock (m_pauseLock) { 92 lock (m_pauseLock) {