예제 #1
0
 public void Unload()
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         if (_runtime == null || _runtime.GetService <WorkflowPersistenceService>() == null)
         {
             throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.MissingPersistenceService, this.InstanceId));
         }
         while (true)
         {
             WorkflowExecutor executor = _runtime.Load(this);
             if (executor.IsInstanceValid)
             {
                 try
                 {
                     executor.Unload();
                     return;
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
                 catch (ExecutorLocksHeldException e)
                 {
                     try
                     {
                         e.Handle.WaitOne(/* maybe should have a timeout here?*/);
                     }
                     catch (ObjectDisposedException)
                     {
                         // If an ObjectDisposedException is thrown because
                         // the WaitHandle has already closed, nothing to worry
                         // about. Move on.
                     }
                 }
             }
         }
     }
 }