Esempio n. 1
0
        internal sealed override void InternalExecute(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            AsyncOperationContext asyncContext = executor.SetupAsyncOperationBlock(instance);

            instance.IncrementBusyCount();
            AsyncCodeActivityContext context = new AsyncCodeActivityContext(asyncContext, instance, executor);
            bool flag = false;

            try
            {
                IAsyncResult result = this.BeginExecute(context, AsyncCodeActivity.OnExecuteComplete, asyncContext);
                if (result == null)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.BeginExecuteMustNotReturnANullAsyncResult));
                }
                if (!object.ReferenceEquals(result.AsyncState, asyncContext))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.BeginExecuteMustUseProvidedStateAsAsyncResultState));
                }
                if (result.CompletedSynchronously)
                {
                    ((IAsyncCodeActivity)this).FinishExecution(context, result);
                    asyncContext.CompleteOperation();
                }
                flag = true;
            }
            finally
            {
                context.Dispose();
                if (!flag)
                {
                    asyncContext.CancelOperation();
                }
            }
        }
        sealed internal override void InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            // first set up an async context
            AsyncOperationContext asyncContext = executor.SetupAsyncOperationBlock(instance);

            instance.IncrementBusyCount();

            AsyncCodeActivityContext context = new AsyncCodeActivityContext(asyncContext, instance, executor);
            bool success = false;

            try
            {
                IAsyncResult result = BeginExecute(context, AsyncCodeActivity.OnExecuteComplete, asyncContext);

                if (result == null)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.BeginExecuteMustNotReturnANullAsyncResult));
                }

                if (!object.ReferenceEquals(result.AsyncState, asyncContext))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.BeginExecuteMustUseProvidedStateAsAsyncResultState));
                }

                if (result.CompletedSynchronously)
                {
                    EndExecute(context, result);
                    asyncContext.CompleteOperation();
                }
                success = true;
            }
            finally
            {
                context.Dispose();
                if (!success)
                {
                    asyncContext.CancelOperation();
                }
            }
        }