Exemple #1
0
        public void TestAbortOneRunningTask()
        {
            DummyTaskParameters params1 = new DummyTaskParameters();

            params1.IsBackgroundTask  = true;
            params1.Name              = "TestRunOneTask";
            params1.RunInParallel     = false;
            params1.UseSeparateThread = true;
            params1.WaitForAbort      = true;

            DummyTask task1 = new DummyTask(params1);

            // Create a task manager for the context.
            TaskManager taskManager = new TaskManager("Test");

            taskManager.Enqueue(task1);

            // Give it a second to start running the task then abort.
            Thread.Sleep(1000);
            taskManager.AbortCurrentTask(true);

            taskManager.WaitForTaskCompletion(task1, s_TaskTimeout);

            Assert.AreEqual(1, task1.ExecutionCount);
            Assert.AreNotEqual(null, task1.LastException);
            Assert.AreEqual(true, task1.CurrentTaskState.TaskCompleted);
            Assert.AreEqual(true, task1.CurrentTaskState.Aborted);
            Assert.AreEqual(true, task1.CurrentTaskState.ExternalAbortRequested);
            taskManager.Dispose();
        }