comparison Implab/Parallels/AsyncPool.cs @ 48:d9d794b61bb9 interactive logger

Interactive tracing Improved working with tracing contexts
author cin
date Fri, 18 Apr 2014 12:34:45 +0400
parents d10034588e38
children 790e8a997d30
comparison
equal deleted inserted replaced
47:b181f7bcb259 48:d9d794b61bb9
15 public static IPromise<T> Invoke<T>(Func<T> func) { 15 public static IPromise<T> Invoke<T>(Func<T> func) {
16 var p = new Promise<T>(); 16 var p = new Promise<T>();
17 var caller = TraceContext.Snapshot(); 17 var caller = TraceContext.Snapshot();
18 18
19 ThreadPool.QueueUserWorkItem(param => { 19 ThreadPool.QueueUserWorkItem(param => {
20 TraceContext.Transfer(caller); 20 TraceContext.Fork(caller);
21 try { 21 try {
22 p.Resolve(func()); 22 p.Resolve(func());
23 } catch(Exception e) { 23 } catch(Exception e) {
24 p.Reject(e); 24 p.Reject(e);
25 } 25 }
32 var p = new Promise<T>(); 32 var p = new Promise<T>();
33 33
34 var caller = TraceContext.Snapshot(); 34 var caller = TraceContext.Snapshot();
35 35
36 var worker = new Thread(() => { 36 var worker = new Thread(() => {
37 TraceContext.Transfer(caller); 37 TraceContext.Fork(caller);
38 try { 38 try {
39 p.Resolve(func()); 39 p.Resolve(func());
40 } catch (Exception e) { 40 } catch (Exception e) {
41 p.Reject(e); 41 p.Reject(e);
42 } 42 }
44 worker.IsBackground = true; 44 worker.IsBackground = true;
45 worker.Start(); 45 worker.Start();
46 46
47 return p; 47 return p;
48 } 48 }
49
50
51 public static IPromiseBase InvokeNewThread(Action func) {
52 var p = new Promise<object>();
53
54 var caller = TraceContext.Snapshot();
55
56 var worker = new Thread(() => {
57 TraceContext.Fork(caller);
58 try {
59 func();
60 p.Resolve();
61 } catch (Exception e) {
62 p.Reject(e);
63 }
64 });
65 worker.IsBackground = true;
66 worker.Start();
67
68 return p;
69 }
49 } 70 }
50 } 71 }