}
}
+ class NonInlineableScheduler : TaskScheduler
+ {
+ protected override IEnumerable<Task> GetScheduledTasks ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override void QueueTask (Task task)
+ {
+ if (!base.TryExecuteTask (task))
+ throw new ApplicationException ();
+ }
+
+ protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
+ {
+ return false;
+ }
+ }
+
Task[] tasks;
const int max = 6;
Assert.IsTrue (r2);
}
+ [Test]
+ public void AsyncWaitHandleSet ()
+ {
+ var task = new TaskFactory ().StartNew (() => { });
+ var ar = (IAsyncResult)task;
+ ar.AsyncWaitHandle.WaitOne ();
+ }
+
#if NET_4_5
[Test]
public void Delay_Invalid ()
}
}
+ [Test]
+ public void Delay_TimeManagement ()
+ {
+ var delay1 = Task.Delay(50);
+ var delay2 = Task.Delay(25);
+ Assert.IsTrue (Task.WhenAny(new[] { delay1, delay2 }).Wait (1000));
+ Assert.AreEqual (TaskStatus.RanToCompletion, delay2.Status);
+ }
+
[Test]
public void WaitAny_WithNull ()
{
}
}
+ [Test]
+ public void WhenAll_Empty ()
+ {
+ var tasks = new Task[0];
+
+ Task t = Task.WhenAll(tasks);
+
+ Assert.IsTrue(t.Wait(1000), "#1");
+ }
+
[Test]
public void WhenAll_WithNull ()
{
Assert.IsTrue (t.Wait (1000), "#2");
}
+ [Test]
+ public void WhenAllResult_Empty ()
+ {
+ var tasks = new Task<int>[0];
+
+ Task<int[]> t = Task.WhenAll(tasks);
+
+ Assert.IsTrue(t.Wait(1000), "#1");
+ Assert.IsNotNull(t.Result, "#2");
+ Assert.AreEqual(t.Result.Length, 0, "#3");
+ }
+
[Test]
public void WhenAllResult_WithNull ()
{
Assert.AreEqual ('d', d.Result, "#3r");
}
+ [Test]
+ public void ContinueWith_CustomScheduleRejected ()
+ {
+ var scheduler = new NonInlineableScheduler ();
+ var t = Task.Factory.StartNew (delegate { }).
+ ContinueWith (r => {}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, scheduler);
+
+ Assert.IsTrue (t.Wait (5000));
+ }
+
[Test]
public void FromResult ()
{