void RaiseWorkCompletedEventFromClientContext(object state) { OperationInfo opInfo = (OperationInfo)state; RunWorkerCompletedEventArgsWithUserState eventArgs = opInfo.OperationResult; Delegate[] targets; lock (_operationCompletedLock) { targets = _operationCompleted.GetInvocationList(); } foreach (RunWorkerCompletedWithUserStateEventHandler handler in targets) { try { handler(this, eventArgs); } catch { } } // Now that we're done calling back to the client to let them know // that the operation has completed, remove this operation from the // queue and check to see if we need to start another operation. // OperationRequest opRequest = opInfo.OperationRequest; OperationInfo nextOp = null; lock (_collectionsLock) { if ((_operationQueue.Peek() != opInfo) || !_userStateToOperationMap.ContainsKey(opRequest.UserState)) { throw new InvalidOperationException("Something freaky happened."); } _operationQueue.Dequeue(); _userStateToOperationMap.Remove(opInfo); if (_operationQueue.Count > 0) { nextOp = _operationQueue.Peek(); } else { _cancelAllPending = false; } } if (nextOp != null) { // We have more work items pending. Kick off another operation. // nextOp.OperationRequest.OperationHandler.BeginInvoke(nextOp, OperationHandlerDone, nextOp); } }
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgsWithUserState e) { if (e.Cancelled) { //Operation was cancelled } else if (e.Error != null) { //Asynchronous operation failed } else { //Success } activeThreadCount--; if (activeThreadCount == 0) { ApplicationContext.Current.SetStatusBar(Languages.Translate("Ready"), 100); } }
internal OperationInfo(OperationRequest request) { _request = request; _result = null; }