Exemplo n.º 1
0
        public void TestCancel()
        {
            using (var waitHandle = new ManualResetEvent(false))
            {
                // Monitor for a cancellation exception
                var  task                    = new WaitTask("Test task", waitHandle);
                bool exceptionThrown         = false;
                var  cancellationTokenSource = new CancellationTokenSource();
                var  waitThread              = new Thread(() =>
                {
                    try
                    {
                        task.Run(cancellationTokenSource.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        exceptionThrown = true;
                    }
                });

                // Start and then cancel the download
                waitThread.Start();
                Thread.Sleep(100);
                cancellationTokenSource.Cancel();
                waitThread.Join();

                exceptionThrown.Should().BeTrue(because: task.State.ToString());
            }
        }
Exemplo n.º 2
0
        public void TestCancel()
        {
            using (var waitHandle = new ManualResetEvent(false))
            {
                // Monitor for a cancellation exception
                var task = new WaitTask("Test task", waitHandle);
                bool exceptionThrown = false;
                var cancellationTokenSource = new CancellationTokenSource();
                var waitThread = new Thread(() =>
                {
                    try
                    {
                        task.Run(cancellationTokenSource.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        exceptionThrown = true;
                    }
                });

                // Start and then cancel the download
                waitThread.Start();
                Thread.Sleep(100);
                cancellationTokenSource.Cancel();
                waitThread.Join();

                exceptionThrown.Should().BeTrue(because: task.State.ToString());
            }
        }
Exemplo n.º 3
0
        public void TestWait()
        {
            using (var waitHandle = new ManualResetEvent(false))
            {
                var task       = new WaitTask("Test task", waitHandle);
                var waitThread = new Thread(() => task.Run());
                waitThread.Start();

                Thread.Sleep(100);
                task.State.Should().Be(TaskState.Started);

                waitHandle.Set();
                waitThread.Join();
                task.State.Should().Be(TaskState.Complete);
            }
        }
Exemplo n.º 4
0
        public void TestWait()
        {
            using (var waitHandle = new ManualResetEvent(false))
            {
                var task = new WaitTask("Test task", waitHandle);
                var waitThread = new Thread(() => task.Run());
                waitThread.Start();

                Thread.Sleep(100);
                task.State.Should().Be(TaskState.Started);

                waitHandle.Set();
                waitThread.Join();
                task.State.Should().Be(TaskState.Complete);
            }
        }