Exemplo n.º 1
0
        /// <summary>
        /// Use BeginInvoke/EndInvoke
        /// </summary>
        private static void WorkflowInvokerBeginInvoke()
        {
            Console.WriteLine("Host: About to run workflow - Thread:{0}",
                              System.Threading.Thread.CurrentThread.ManagedThreadId);

            try
            {
                WorkflowInvoker instance = new WorkflowInvoker(
                    new HostingDemoWorkflow {
                    ArgNumberToEcho = 1001
                });
                IAsyncResult ar = instance.BeginInvoke(
                    BeginInvokeCallback, instance);

                Console.WriteLine(
                    "Host: Workflow started - Thread:{0}",
                    System.Threading.Thread.CurrentThread.ManagedThreadId);
                waitEvent.WaitOne();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Host: Workflow exception:{0}:{1}",
                                  exception.GetType(), exception.Message);
            }
        }
Exemplo n.º 2
0
        private void InvokeReputation()
        {
            object state   = "";
            var    invoker = new WorkflowInvoker(new UnfreezeTextWorkflow());
            var    inputs  = new Dictionary <string, object> {
            };

            // Wait for the workflow to complete.
            Task.Factory.FromAsync <IDictionary <string, object> >(
                invoker.BeginInvoke(inputs, AsyncCall, state),
                invoker.EndInvoke);
        }
Exemplo n.º 3
0
        // BeginInvoke with LongRunningDiceRoll
        //<snippet32>
        static void BeginInvokeExample()
        {
            WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

            string       userState = "BeginInvoke example";
            IAsyncResult result    = invoker.BeginInvoke(new AsyncCallback(WorkflowCompletedCallback), userState);

            // You can inspect result from the host to determine if the workflow
            // is complete.
            Console.WriteLine("result.IsCompleted: {0}", result.IsCompleted);

            // The results of the workflow are retrieved by calling EndInvoke, which
            // can be called from the callback or from the host. If called from the
            // host, it blocks until the workflow completes. If a callback is not
            // required, pass null for the callback parameter.
            Console.WriteLine("Waiting for the workflow to complete.");
            IDictionary <string, object> outputs = invoker.EndInvoke(result);

            Console.WriteLine("The two dice are {0} and {1}.",
                              outputs["D1"], outputs["D2"]);
        }