/// <summary>
            /// Initializes a new instance of the <see cref="InvokeAsyncResult"/> class.
            /// </summary>
            /// <param name="activity">The activity.</param>
            /// <param name="inputs">The inputs.</param>
            /// <param name="extensions">The extensions.</param>
            /// <param name="timeout">The timeout.</param>
            /// <param name="syncContext">The synchronize context.</param>
            /// <param name="invokeContext">The invoke context.</param>
            /// <param name="callback">The callback.</param>
            /// <param name="state">The state.</param>
            public InvokeAsyncResult(
                Activity activity,
                IDictionary <string, object> inputs,
                WorkflowInstanceExtensionManager extensions,
                TimeSpan timeout,
                SynchronizationContext syncContext,
                AsyncInvokeContext invokeContext,
                AsyncCallback callback,
                object state)
                : base(callback, state)
            {
                if (activity == null)
                {
                    throw new ArgumentNullException(nameof(activity));
                }

                this.completionWaiter = new AsyncWaitHandle();
                syncContext ??= SynchronousSynchronizationContext.Value;

                this.instance = WorkflowApplication.StartInvoke(activity, inputs, extensions, syncContext, new Action(this.OnInvokeComplete), invokeContext);

                if (this.completionWaiter.WaitAsync(WaitCompleteCallback, this, timeout))
                {
                    var completeSelf = this.OnWorkflowCompletion();

                    if (completeSelf)
                    {
                        if (this.completionException != null)
                        {
                            throw FxTrace.Exception.AsError(this.completionException);
                        }
                        else
                        {
                            this.Complete(true);
                        }
                    }
                }
            }