var arr = new [] { a, b };
string res = null;
- Task<int> t = Task.Run (() => BlockingCollection<string>.TakeFromAny (arr, out res));
+ Task<int> t = Task.Factory.StartNew (() => BlockingCollection<string>.TakeFromAny (arr, out res));
a.Add ("foo");
Assert.AreEqual (0, t.Result, "#1");
Assert.AreEqual ("foo", res, "#2");
- t = Task.Run (() => BlockingCollection<string>.TakeFromAny (arr, out res));
+ t = Task.Factory.StartNew (() => BlockingCollection<string>.TakeFromAny (arr, out res));
b.Add ("bar");
Assert.AreEqual (1, t.Result, "#3");
Assert.AreEqual ("bar", res, "#4");
var cts = new CancellationTokenSource ();
string res = null;
- Task<int> t = Task.Run (() => BlockingCollection<string>.TakeFromAny (arr, out res, cts.Token));
+ Task<int> t = Task.Factory.StartNew (() => BlockingCollection<string>.TakeFromAny (arr, out res, cts.Token));
Thread.Sleep (100);
a.Add ("foo");
Assert.AreEqual (0, t.Result, "#1");
Assert.AreEqual ("foo", res, "#2");
- t = Task.Run (() => BlockingCollection<string>.TakeFromAny (arr, out res, cts.Token));
+ t = Task.Factory.StartNew (() => BlockingCollection<string>.TakeFromAny (arr, out res, cts.Token));
Thread.Sleep (100);
b.Add ("bar");
Assert.AreEqual (1, t.Result, "#3");
Assert.AreEqual ("bar", res, "#4");
- t = Task.Run (() => {
+ t = Task.Factory.StartNew (() => {
try {
return BlockingCollection<string>.TakeFromAny (arr, out res, cts.Token);
- } catch (OperationCanceledException WE_GOT_CANCELED) {
+ } catch (OperationCanceledException) {
res = "canceled";
return -10;
}