Exemplo n.º 1
0
        public void catch_happens_before_finally_with_CurrentThreadScheduler()
        {
            var task1HasRun = false;
            var task2HasRun = false;
            var task3HasRun = false;

            var scheduler = new CurrentThreadTaskScheduler();

            new TaskFactory(scheduler)
            .StartNew(() =>
            {
                Assert.That(task1HasRun, Is.False);
                Assert.That(task2HasRun, Is.False);
                Assert.That(task3HasRun, Is.False);
                task1HasRun = true;

                throw new Exception();
            })
            .CatchAndHandle(_ =>
            {
                Assert.That(task1HasRun, Is.True);
                Assert.That(task2HasRun, Is.False);
                Assert.That(task3HasRun, Is.False);
                task2HasRun = true;
            }, scheduler)
            .Finally(() =>
            {
                Assert.That(task1HasRun, Is.True);
                Assert.That(task2HasRun, Is.True);
                Assert.That(task3HasRun, Is.False);
                task3HasRun = true;
            }, scheduler);

            Assert.That(task1HasRun, Is.True);
            Assert.That(task2HasRun, Is.True);
            Assert.That(task3HasRun, Is.True);
        }
Exemplo n.º 2
0
        public void catch_happens_before_finally_with_CurrentThreadScheduler()
        {
            var task1HasRun = false;
            var task2HasRun = false;
            var task3HasRun = false;

            var scheduler = new CurrentThreadTaskScheduler();

            new TaskFactory(scheduler)
                .StartNew(() =>
                {
                    Assert.That(task1HasRun, Is.False);
                    Assert.That(task2HasRun, Is.False);
                    Assert.That(task3HasRun, Is.False);
                    task1HasRun = true;

                    throw new Exception();
                })
                .CatchAndHandle(_ =>
                {
                    Assert.That(task1HasRun, Is.True);
                    Assert.That(task2HasRun, Is.False);
                    Assert.That(task3HasRun, Is.False);
                    task2HasRun = true;
                }, scheduler)
                .Finally(() =>
                {
                    Assert.That(task1HasRun, Is.True);
                    Assert.That(task2HasRun, Is.True);
                    Assert.That(task3HasRun, Is.False);
                    task3HasRun = true;
                }, scheduler);

            Assert.That(task1HasRun, Is.True);
            Assert.That(task2HasRun, Is.True);
            Assert.That(task3HasRun, Is.True);
        }
Exemplo n.º 3
0
 public TestTaskScheduler()
 {
     Default = new CurrentThreadTaskScheduler();
 }