Example #1
0
        public void CancelTest()
        {
            using (var task = new Monitor()) {
                var count = 0;

                task.Execute(token => {
                    while (count != 100)
                    {
                        count++;
                        token.ThrowIfCancellationRequested();
                        Thread.Sleep(100);
                    }
                });

                // Using mono this steps are too fast... #lol
                while (!task.IsRunning)
                {
                    Thread.Sleep(1);
                }

                Assert.True(task.IsRunning);

                task.Cancel();

                Assert.True(task.IsCanceled);
                Assert.False(task.IsRunning);

                Assert.AreNotEqual(100, count);
            };
        }
Example #2
0
        public void CancelTest()
        {
            var task  = new Monitor();
            var count = 0;

            task.Execute(token => {
                while (count != 100)
                {
                    count++;
                    token.ThrowIfCancellationRequested();
                    Thread.Sleep(100);
                }
            });

            Assert.True(task.IsRunning);

            task.Cancel();

            Assert.True(task.IsCanceled);
            Assert.False(task.IsRunning);

            Assert.AreNotEqual(100, count);
        }