comparison Implab/Parallels/AsyncPool.cs @ 40:fe33f4e02ad5

improved tracing added text listeners (file,console)
author cin
date Tue, 15 Apr 2014 17:52:09 +0400
parents 313f708a50e9
children d10034588e38
comparison
equal deleted inserted replaced
39:6498078ae368 40:fe33f4e02ad5
12 /// </remarks> 12 /// </remarks>
13 public static class AsyncPool { 13 public static class AsyncPool {
14 14
15 public static Promise<T> Invoke<T>(Func<T> func) { 15 public static Promise<T> Invoke<T>(Func<T> func) {
16 var p = new Promise<T>(); 16 var p = new Promise<T>();
17 var caller = TraceContext.Current; 17 var caller = TraceContext.Snapshot();
18 18
19 ThreadPool.QueueUserWorkItem(param => { 19 ThreadPool.QueueUserWorkItem(param => {
20 TraceLog.Transfer(caller); 20 TraceContext.Transfer(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 }
29 } 29 }
30 30
31 public static Promise<T> InvokeNewThread<T>(Func<T> func) { 31 public static Promise<T> InvokeNewThread<T>(Func<T> func) {
32 var p = new Promise<T>(); 32 var p = new Promise<T>();
33 33
34 var caller = TraceContext.Current; 34 var caller = TraceContext.Snapshot();
35 35
36 var worker = new Thread(() => { 36 var worker = new Thread(() => {
37 TraceLog.Transfer(caller); 37 TraceContext.Transfer(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 }