コード例 #1
0
        /// <summary>
        /// Constructs a Task object. This is a base class
        /// Creates the thread associated with this task (if a separate on is to be used).
        /// Initialises the Signalling events.
        /// </summary>
        /// <param name="taskParameters">Basic task parameters indicating how task is to be run</param>
        /// <param name="type">Type of task that this is.</param>

        protected Task(TaskParameters taskParameters, StackHashTaskType type)
        {
            if (taskParameters == null)
            {
                throw new ArgumentNullException("taskParameters");
            }

            m_TaskParameters = taskParameters;
            m_TaskType       = type;

            // Default the name if not provided.
            if (m_TaskParameters.Name == null)
            {
                m_TaskParameters.Name = "StackHashTask";
            }

            if (m_TaskParameters.UseSeparateThread)
            {
                m_Thread              = new Thread(new ThreadStart(this.EntryPoint));
                m_Thread.Name         = m_TaskParameters.Name;
                m_Thread.IsBackground = m_TaskParameters.IsBackgroundTask;
            }

            m_Events[s_AbortEvent]  = new ManualResetEvent(false);
            m_Events[s_PauseEvent]  = new ManualResetEvent(false);
            m_Events[s_ResumeEvent] = new ManualResetEvent(false);
        }
コード例 #2
0
        /// <summary>
        /// Gets the status of the task with the specified state.
        /// Only one task of each type will be running.
        /// </summary>
        /// <param name="taskType">Type of task to get status for.</param>
        public virtual StackHashTaskState GetTaskState(StackHashTaskType taskType)
        {
            TaskData currentTask = m_CurrentTask;

            if ((currentTask != null) &&
                (currentTask.ThisTask.TaskType == taskType))
            {
                return(currentTask.TaskStatus.TaskState);
            }


            // Check the queue.
            Monitor.Enter(m_TaskQueue);

            try
            {
                foreach (TaskData taskData in m_TaskQueue)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        return(StackHashTaskState.Queued);
                    }
                }
            }
            finally
            {
                Monitor.Exit(m_TaskQueue);
            }

            // Check the concurrent tasks.
            Monitor.Enter(m_ConcurrentTasks);

            try
            {
                foreach (TaskData taskData in m_ConcurrentTasks)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        return(taskData.TaskStatus.TaskState);
                    }
                }
            }
            finally
            {
                Monitor.Exit(m_ConcurrentTasks);
            }


            return(StackHashTaskState.NotRunning);
        }
コード例 #3
0
        /// <summary>
        /// Aborts all concurrent tasks of the specified type.
        /// </summary>
        /// <param name="taskType">Type of task to abort.</param>
        /// <param name="wait">True - Wait for tasks to complete.</param>
        /// <param name="includeCurrentTask">True - abort current queued task if matching type.</param>
        public virtual void AbortTasksOfType(StackHashTaskType taskType, bool wait, bool includeCurrentTask)
        {
            // First, abort all tasks that are queued but not running.
            Monitor.Enter(m_ConcurrentTasks);

            TaskData currentTask = m_CurrentTask;

            if ((currentTask != null) &&
                includeCurrentTask &&
                (currentTask.ThisTask != null) &&
                (currentTask.ThisTask.TaskType == taskType))
            {
                currentTask.ThisTask.StopExternal();
            }

            List <TaskData> tasksToStop = new List <TaskData>();

            try
            {
                foreach (TaskData taskData in m_ConcurrentTasks)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        tasksToStop.Add(taskData);
                    }
                }

                foreach (TaskData task in tasksToStop)
                {
                    task.ThisTask.StopExternal();

                    if (wait)
                    {
                        task.ThisTask.Join(60000);
                    }
                }

                // The tasks will be removed from the concurrent task loop by the main thread when it receives the
                // TaskCompleted notification.
            }
            finally
            {
                Monitor.Exit(m_ConcurrentTasks);
            }
        }
コード例 #4
0
 /// <summary>
 /// Determines if the client is permitted to abort a task of the specified type.
 /// </summary>
 /// <param name="taskType">Task type to check.</param>
 /// <returns>True - client can abort the task. False - client cannot abort the task.</returns>
 public bool CanTaskBeAbortedByClient(StackHashTaskType taskType)
 {
     if ((taskType == StackHashTaskType.BugReportTask) ||
         (taskType == StackHashTaskType.DebugScriptTask) ||
         (taskType == StackHashTaskType.DownloadCabTask) ||
         (taskType == StackHashTaskType.ErrorIndexCopyTask) ||
         (taskType == StackHashTaskType.ErrorIndexMoveTask) ||
         (taskType == StackHashTaskType.PurgeTask) ||
         (taskType == StackHashTaskType.WinQualSynchronizeTask))
     {
         return(true);
     }
     else
     {
         // The other tasks must remain alive for the profile to work properly.
         return(false);
     }
 }
コード例 #5
0
        /// <summary>
        /// Checks if a task of the specified type is running in any queue.
        /// </summary>
        /// <param name="taskType">The task to check for.</param>
        public virtual bool IsTaskRunning(StackHashTaskType taskType)
        {
            TaskData currentTask = m_CurrentTask;

            // Check the current task running (from the queue).
            if ((currentTask != null) && (currentTask.ThisTask.TaskType == taskType))
            {
                return(true);
            }

            if (IsQueuedTaskRunning(taskType) || (IsConcurrentTaskRunning(taskType)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
        /// <summary>
        /// Returns the first concurrent task of the specified type.
        /// </summary>
        /// <param name="taskType">Type of concurrent task to get.</param>
        public virtual Task GetConcurrentTaskOfType(StackHashTaskType taskType)
        {
            Monitor.Enter(m_ConcurrentTasks);

            try
            {
                foreach (TaskData taskData in m_ConcurrentTasks)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        return(taskData.ThisTask);
                    }
                }

                return(null);
            }
            finally
            {
                Monitor.Exit(m_ConcurrentTasks);
            }
        }
コード例 #7
0
        /// <summary>
        /// Checks the concurrent task list to see if a task of the specified type
        /// is running.
        /// </summary>
        /// <param name="taskType">The task to check for.</param>
        public virtual bool IsConcurrentTaskRunning(StackHashTaskType taskType)
        {
            Monitor.Enter(m_ConcurrentTasks);

            // The mere presence in the list is sufficient as the task will be removed once complete.
            try
            {
                foreach (TaskData taskData in m_ConcurrentTasks)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        return(true);
                    }
                }
            }
            finally
            {
                Monitor.Exit(m_ConcurrentTasks);
            }

            return(false);
        }
コード例 #8
0
        public List <Task> GetTasksOfType(StackHashTaskType taskType)
        {
            List <Task> allTasks = new List <Task>();

            // First, abort all tasks that are queued but not running.
            Monitor.Enter(m_ConcurrentTasks);

            try
            {
                foreach (TaskData taskData in m_ConcurrentTasks)
                {
                    if (taskData.ThisTask.TaskType == taskType)
                    {
                        allTasks.Add(taskData.ThisTask);
                    }
                }

                return(allTasks);
            }
            finally
            {
                Monitor.Exit(m_ConcurrentTasks);
            }
        }
コード例 #9
0
 // use this constructor to abort a task of the specified type
 public WorkerArg(StackHashTaskType taskType, int contextId)
 {
     this.AbortTask = true;
     this.TaskType  = taskType;
     this.ContextId = contextId;
 }
コード例 #10
0
 public StackHashTaskStatus GetTaskStatistics(StackHashTaskType taskType)
 {
     return(null);
 }