Beispiel #1
0
        private void Cleanup(Task task)
        {
            Debug.Assert(task.IsCompleted);
            bool   condition = false;
            bool   lockTaken = false;
            object obj;
            string description;

            try
            {
                Monitor.Enter(obj = this._lock, ref lockTaken);
                if (this._tasks.TryGetValue(task, out description))
                {
                    condition = this._tasks.Remove(task);
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(obj);
                }
            }
            Debug.Assert(condition, description ?? "No description");
            TaskCollector.ReportException(task, description);
        }
Beispiel #2
0
 public void Add(Task task, string description)
 {
     if (task.IsCompleted)
     {
         TaskCollector.ReportException(task, description);
     }
     else
     {
         bool   lockTaken = false;
         object obj;
         try
         {
             Monitor.Enter(obj = this._lock, ref lockTaken);
             Debug.Assert(!this._tasks.ContainsKey(task));
             this._tasks[task] = description;
         }
         finally
         {
             if (lockTaken)
             {
                 Monitor.Exit(obj);
             }
         }
         task.ContinueWith(new Action <Task>(this.Cleanup));
     }
 }