示例#1
0
        /// <summary>
        /// Need to amke sure we cleanup the dataflow links and file watcher
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                CleanupFileWatcher();
                if (FileChangeScheduler != null)
                {
                    FileChangeScheduler.Dispose();
                    FileChangeScheduler = null;
                }

                if (_sequentialTaskQueue != null)
                {
                    _sequentialTaskQueue.Dispose();
                    _sequentialTaskQueue = null;
                }

                if (_broadcastBlock != null)
                {
                    _broadcastBlock.Complete();
                    _broadcastBlock = null;
                }

                if (ProjectRuleSubscriptionLink != null)
                {
                    ProjectRuleSubscriptionLink.Dispose();
                    ProjectRuleSubscriptionLink = null;
                }
            }
        }
示例#2
0
        public void CalltoDisposedObjectShouldThrow()
        {
            var sequencer = new SequencialTaskExecutor();

            sequencer.Dispose();
            Assert.Throws <ObjectDisposedException>(() => { sequencer.ExecuteTask(() => Task.CompletedTask); });
        }
示例#3
0
        public async Task EnsureNestedCallsAreExcecutedDirectly()
        {
            const int NumberOfTasks = 10;
            var       sequencer     = new SequencialTaskExecutor();

            List <Task> tasks     = new List <Task>();
            List <int>  sequences = new List <int>();

            for (int i = 0; i < NumberOfTasks; i++)
            {
                int num = i;
                tasks.Add(sequencer.ExecuteTask(async() =>
                {
                    Func <Task> func = async() =>
                    {
                        await sequencer.ExecuteTask(async() =>
                        {
                            await Task.Delay(1).ConfigureAwait(false);
                            sequences.Add(num);
                        });
                    };
                    await func().ConfigureAwait(false);
                }));
            }

            await Task.WhenAll(tasks.ToArray());

            for (int i = 0; i < NumberOfTasks; i++)
            {
                Assert.Equal(i, sequences[i]);
            }
        }
示例#4
0
        public async Task EnsureTasksCancelledWhenDisposed()
        {
            const int NumberOfTasks = 10;
            var       sequencer     = new SequencialTaskExecutor();

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < NumberOfTasks; i++)
            {
                int num = i;
                tasks.Add(sequencer.ExecuteTask(async() =>
                {
                    Func <Task> func = async() =>
                    {
                        await Task.Delay(100).ConfigureAwait(false);
                    };
                    await func().ConfigureAwait(false);
                }));
            }
            sequencer.Dispose();

            try
            {
                await Task.WhenAll(tasks.ToArray());

                Assert.False(true);
            }
            catch (OperationCanceledException)
            {
                bool mustBeCancelled = false;
                for (int i = 0; i < NumberOfTasks; i++)
                {
                    // The first task or two may already be running. So we skip completed tasks until we find
                    // one that is is cancelled
                    if (mustBeCancelled)
                    {
                        Assert.True(tasks[i].IsCanceled);
                    }
                    else
                    {
                        // All remaining tasks should be cancelled
                        mustBeCancelled = tasks[i].IsCanceled;
                    }
                }

                Assert.True(mustBeCancelled);
            }
        }