Exemplo n.º 1
0
        private void Cleanup(Task task)
        {
            Debug.Assert(task.IsCompleted);
            bool   condition = false;
            bool   lockTaken = false;
            object obj       = null;
            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);
        }
Exemplo n.º 2
0
 public void Add(Task task, string description)
 {
     if (task.IsCompleted)
     {
         TaskCollector.ReportException(task, description);
     }
     else
     {
         bool   lockTaken = false;
         object obj       = null;
         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));
     }
 }