##// END OF EJS Templates
fix
fix

File last commit:

r239:eedf4d834e67 v2
r239:eedf4d834e67 v2
Show More
InteractiveListener.cs
147 lines | 4.5 KiB | text/x-csharp | CSharpLexer
cin
refactoring, interactive tarce log almost complete
r47 using Implab.Parallels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Implab.Diagnostics.Interactive
{
cin
Improved logging
r134 public class InteractiveListener: ListenerBase
cin
refactoring, interactive tarce log almost complete
r47 {
TraceForm m_form;
SynchronizationContext m_syncGuiThread;
cin
fixed Resove method bug when calling it on already cancelled promise
r130 readonly Promise m_guiStarted = new Promise();
cin
refactoring, interactive tarce log almost complete
r47
cin
Refactoring
r66 readonly IPromise m_guiFinished;
cin
refactoring, interactive tarce log almost complete
r47
cin
fix
r239 readonly SimpleAsyncQueue<TraceViewItem> m_queue = new SimpleAsyncQueue<TraceViewItem>();
cin
refactoring, interactive tarce log almost complete
r47 readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false);
int m_queueLength;
bool m_exitPending;
readonly object m_pauseLock = new object();
bool m_paused;
readonly ManualResetEvent m_pauseEvent = new ManualResetEvent(true);
cin
Improved logging
r134 public InteractiveListener() {
cin
Fixed InteractiveListener to support OLE and clipboard....
r215 m_guiFinished = RunGuiThread();
AsyncPool.RunThread(QueueThread);
cin
refactoring, interactive tarce log almost complete
r47
m_guiStarted.Join();
}
void GuiThread() {
m_form = new TraceForm(); // will create SynchronizationContext
cin
Interactive tracing...
r48
m_form.PauseEvents += (s,a) => Pause();
m_form.ResumeEvents += (s, a) => Resume();
cin
refactoring, interactive tarce log almost complete
r47 m_syncGuiThread = SynchronizationContext.Current;
m_guiStarted.Resolve();
Application.Run();
}
void QueueThread() {
while (!m_exitPending) {
if (m_paused)
m_pauseEvent.WaitOne();
TraceViewItem item;
if (m_queue.TryDequeue(out item)) {
Interlocked.Decrement(ref m_queueLength);
cin
Added the time delta column to the interactive trace listener
r214 m_syncGuiThread.Post(x => m_form.AddTraceEvent(item),null);
cin
refactoring, interactive tarce log almost complete
r47 } else {
m_queueEvent.WaitOne();
}
}
}
cin
Fixed InteractiveListener to support OLE and clipboard....
r215 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;
}
cin
refactoring, interactive tarce log almost complete
r47 public void Pause() {
// for consistency we need to set this properties atomically
lock (m_pauseLock) {
m_pauseEvent.Reset();
m_paused = true;
}
}
public void Resume() {
// for consistency we need to set this properties atomically
lock (m_pauseLock) {
m_paused = false;
m_pauseEvent.Set();
}
}
void Enqueue(TraceViewItem item) {
m_queue.Enqueue(item);
if (Interlocked.Increment(ref m_queueLength) == 1)
m_queueEvent.Set();
}
public void ShowForm() {
m_syncGuiThread.Post(x => m_form.Show(), null);
}
public void HideForm() {
m_syncGuiThread.Post(x => m_form.Hide(), null);
}
void Terminate() {
cin
Interactive tracing...
r48 m_exitPending = true;
Resume();
cin
refactoring, interactive tarce log almost complete
r47 m_syncGuiThread.Post(x => Application.ExitThread(), null);
}
protected override void Dispose(bool disposing) {
if (disposing) {
Terminate();
m_guiFinished.Join();
}
base.Dispose(disposing);
}
cin
Interactive tracing...
r48
cin
Improved logging
r134 public override void Write(LogEventArgs args, object entry) {
cin
Interactive tracing...
r48 var item = new TraceViewItem {
cin
Improved logging
r134 Indent = args.Operation.Level,
Message = entry.ToString(),
cin
rewritten tracing
r92 Thread = args.ThreadId,
cin
Fixed broken Implab.Diagnostics.Interactive
r204 Channel = args.Channel.ToString(),
cin
Added the time delta column to the interactive trace listener
r214 Timestamp = Environment.TickCount,
TimeDelta = args.OperationTimeOffset
cin
Interactive tracing...
r48 };
Enqueue(item);
}
cin
refactoring, interactive tarce log almost complete
r47 }
}