comparison 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
comparison
equal deleted inserted replaced
42:3ba6778ed336 45:d10034588e38
1 using Implab.Parallels;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading;
7 using System.Threading.Tasks;
8 using System.Windows.Forms;
9
10 namespace Implab.Diagnostics.Interactive
11 {
12 public class InteractiveTracer: Disposable
13 {
14 TraceForm m_form;
15 SynchronizationContext m_syncGuiThread;
16 readonly IPromiseBase m_completed;
17 readonly Promise<object> m_started = new Promise<object>();
18
19 public InteractiveTracer() {
20 m_completed = AsyncPool.InvokeNewThread(() => {
21 GuiThread();
22 return 0;
23 });
24
25 m_started.Join();
26 }
27
28 void GuiThread() {
29 m_form = new TraceForm(); // will create SynchronizationContext
30 m_syncGuiThread = SynchronizationContext.Current;
31 m_started.Resolve();
32 Application.Run();
33 }
34
35 public void ShowForm() {
36 m_syncGuiThread.Post(x => m_form.Show(), null);
37 }
38
39 public void HideForm() {
40 m_syncGuiThread.Post(x => m_form.Hide(), null);
41 }
42
43 void Terminate() {
44 m_syncGuiThread.Post(x => Application.ExitThread(), null);
45 }
46
47 protected override void Dispose(bool disposing) {
48 if (disposing) {
49 Terminate();
50 m_completed.Join();
51 }
52 base.Dispose(disposing);
53 }
54 }
55 }