Mercurial > pub > ImplabNet
diff Implab.Diagnostics.Interactive/InteractiveTracer.cs @ 45:d10034588e38 interactive logger
initial work on interactive logger
author | cin |
---|---|
date | Thu, 17 Apr 2014 03:05:53 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.Diagnostics.Interactive/InteractiveTracer.cs Thu Apr 17 03:05:53 2014 +0400 @@ -0,0 +1,55 @@ +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 +{ + public class InteractiveTracer: Disposable + { + TraceForm m_form; + SynchronizationContext m_syncGuiThread; + readonly IPromiseBase m_completed; + readonly Promise<object> m_started = new Promise<object>(); + + public InteractiveTracer() { + m_completed = AsyncPool.InvokeNewThread(() => { + GuiThread(); + return 0; + }); + + m_started.Join(); + } + + void GuiThread() { + m_form = new TraceForm(); // will create SynchronizationContext + m_syncGuiThread = SynchronizationContext.Current; + m_started.Resolve(); + Application.Run(); + } + + public void ShowForm() { + m_syncGuiThread.Post(x => m_form.Show(), null); + } + + public void HideForm() { + m_syncGuiThread.Post(x => m_form.Hide(), null); + } + + void Terminate() { + m_syncGuiThread.Post(x => Application.ExitThread(), null); + } + + protected override void Dispose(bool disposing) { + if (disposing) { + Terminate(); + m_completed.Join(); + } + base.Dispose(disposing); + } + } +}