示例#1
0
        private void CleanUpZombieTasks()
        {
            while (true)
            {
                lock (typeof(TaskManager))
                {
                    DateTime    now             = DateTime.Now;
                    List <Guid> entriesToDelete = new List <Guid>();

                    foreach (Guid key in this.dctTasks.Keys)
                    {
                        TaskDescription td = this.dctTasks[key];

                        if (td.CreationDateTime.Subtract(now).TotalMinutes > 15)
                        {
                            if (td.Thread.ThreadState == ThreadState.Running)
                            {
                                td.Thread.Abort();
                            }

                            entriesToDelete.Add(key);
                        }
                    }

                    foreach (Guid key in entriesToDelete)
                    {
                        this.dctTasks.Remove(key);
                    }
                }

                Thread.Sleep((int)TimeSpan.FromMinutes(15).TotalMilliseconds);
            }
        }
示例#2
0
        public XElement QueryTask(Guid taskId)
        {
            TaskDescription td = null;

            lock (typeof(TaskManager))
            {
                if (!this.dctTasks.ContainsKey(taskId))
                {
                    //throw new InvalidOperationException("Task not found.");
                    return(new XElement("root", new XElement("status", "ignored")));
                }

                td = this.dctTasks[taskId];
            }

            return(td.Task.Query());
        }
示例#3
0
        public void TerminateTask(Guid taskId)
        {
            TaskDescription td = null;

            lock (typeof(TaskManager))
            {
                if (this.dctTasks.ContainsKey(taskId))
                {
                    td = this.dctTasks[taskId];
                    this.dctTasks.Remove(taskId);
                }
            }

            if (td != null)
            {
                td.Thread.Abort();
            }
        }
示例#4
0
        public string GetResult(Guid taskId)
        {
            TaskDescription td = null;

            lock (typeof(TaskManager))
            {
                if (!this.dctTasks.ContainsKey(taskId))
                {
                    throw new InvalidOperationException("Task not found.");
                }

                td = this.dctTasks[taskId];

                if (td.Thread.ThreadState == ThreadState.Running)
                {
                    throw new InvalidOperationException("Cannot get result from task that is running.");
                }

                this.dctTasks.Remove(taskId);
            }

            return(td.Task.GetResult());
        }