Ejemplo n.º 1
0
        public async Task TestRunRepeated1()   // Aligned with the coroutine test TestExecuteRepeated1
        {
            var counter = 0;
            var cancel  = new CancellationTokenSource();
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                TaskV2.RunRepeated(async() => {
                    await TaskV2.Delay(1);
                    counter++;
                    return(counter < 3); // stop repeated execution once 3 is reached
                }, delayInMsBetweenIterations: 300, cancelToken: cancel.Token, delayInMsBeforeFirstExecution: 200);
#pragma warning restore CS4014           // Because this call is not awaited, execution of the current method continues before the call is completed
            }
            {                            // while the repeated task is running check over time if the counter increases:
                await TaskV2.Delay(100);

                Assert.Equal(0, counter);
                await TaskV2.Delay(200);

                Assert.Equal(1, counter);
                await TaskV2.Delay(300);

                Assert.Equal(2, counter);
                await TaskV2.Delay(300);

                Assert.Equal(3, counter);
                await TaskV2.Delay(300);

                Assert.Equal(3, counter);
            }
            cancel.Cancel();
        }