コード例 #1
0
 public void Error(AppOperation op, Exception ex)
 {
     if (op.State != OperationState.Running)
     {
         return;
     }
     lock (operations)
     {
         operations.Remove(op);
     }
     op.Stop(true);
     currentOperation.Value = null;
     op.Exception           = ex;
     Interlocked.Increment(ref failedOperations);
     //add the op to the error operation list
     lock (errorOperations)
     {
         errorOperations.AddLast(op);
         if (errorOperations.Count > MaxErrorOperations)
         {
             errorOperations.RemoveFirst();
         }
     }
     //record to database
     statsService.LogFailedTask(op, ErrorReason.Exception);
 }
コード例 #2
0
 public void Done(AppOperation op)
 {
     if (op.State != OperationState.Running)
     {
         return;
     }
     lock (operations)
     {
         operations.Remove(op);
     }
     op.Stop(false);
     currentOperation.Value = null;
     Interlocked.Increment(ref successedOperations);
     //record long operations
     lock (prolongOperations)
     {
         var to = new TimedOperation(op);
         if (prolongOperations.Count > 0 && to.Duration <= prolongOperations[0].Duration)
         {
             return;
         }
         int i = prolongOperations.BinarySearch(to);
         if (i < 0)
         {
             i = ~i;
             if (i == prolongOperations.Count)
             {
                 prolongOperations.Add(to);
             }
             else
             {
                 prolongOperations.Insert(i, to);
             }
         }
         else
         {
             prolongOperations.Insert(i, to);
         }
         if (prolongOperations.Count > MaxProlongOperations)
         {
             prolongOperations.RemoveAt(0);
         }
     }
 }