Created
November 2, 2011 17:21
-
-
Save samoshkin/1334279 to your computer and use it in GitHub Desktop.
Call context with child threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CallContext.SetData("key", new Number { N = 1 }); | |
var task1 = Task.Factory.StartNew(() => | |
{ | |
var n = CallContext.GetData("key") as Number; | |
n.N++; | |
Thread.Sleep(1000); | |
}); | |
var task2 = Task.Factory.StartNew(() => | |
{ | |
var n = CallContext.GetData("key") as Number; | |
n.N++; | |
Thread.Sleep(1000); | |
}); | |
Task.WaitAll(task1, task2); | |
LoggingUtils.TraceMessageF("Result number: {0}", (CallContext.GetData("key") as Number).N); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment