Ejemplo n.º 1
0
        private void RaiseWorkCompletedEventFromClientContext(object state)
        {
            OperationInfo opInfo = (OperationInfo)state;
            RunWorkerCompletedEventArgsWithUserState eventArgs = opInfo.OperationResult;

            Delegate[] targets;

            lock (_operationCompletedLock)
            {
                targets = _operationCompleted.GetInvocationList();
            }

            foreach (RunWorkerCompletedEventHandler handler in targets)
            {
                try
                {
                    handler(this, eventArgs);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("---{0}:RaiseWorkCompletedEventFromClientContext, exception caught : {1}", this.ToString(), ex.Message));
                    //throw ex;
                }
            }

            // 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);
            }
        }
Ejemplo n.º 2
0
 internal OperationInfo(OperationRequest request)
 {
     _request = request;
     _result  = null;
 }