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