Пример #1
0
        public void CancelTest()
        {
            Exception ex = null;

            GA.GlobalError += (ss, ee) =>
            {
                ex = ee.Exception;
            };
            int testCount = 0;
            var token     = Ajob.Loop(j =>
            {
                j.Delay(5000);
                if (!j.IsCanceled)
                {
                    testCount++;
                }
            }, 300);

            Threading.Thread.Sleep(1000);
            token.Cancel();
            Assert.Equal(0, testCount);
            Threading.Thread.Sleep(5000);

            Assert.True(token.IsCanceled);
            Assert.Equal(0, testCount);
            Assert.Null(ex);
        }
Пример #2
0
        public void LoopTest()
        {
            int testCount = 0;
            var token     = Ajob.Loop(j => testCount++, 300);

            token.Wait(1000);
            token.Cancel();
            Assert.Equal(3, testCount);
            Threading.Thread.Sleep(1000);
            Assert.Equal(3, testCount);
        }