Click here to Skip to main content
15,897,891 members
Articles / Programming Languages / C#

Microsoft Windows Workflow Foundation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
31 Aug 2009CPOL12 min read 74.5K   1.6K   52  
An artilce that explains how to call external data and methods.
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime;
using System.Threading;

namespace WorkflowInvoker
{
    class Program
    {
        private static AutoResetEvent waitHandle = new AutoResetEvent(false);
        static void Main(string[] args)
        {
            // Obtain a workflow runtime object.
            WorkflowRuntime workflowRuntime = WorkflowFactory.GetWorkflowRuntime();

            // Add the event handlers.
            workflowRuntime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(workflowIdled);
            workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(workflowCompleted);
            workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(workflowTerminated);

            // Print banner.
            Console.WriteLine("Waiting for workflow completion.");

            // Wait for the workflow to complete.
            waitHandle.WaitOne();

            // Print banner.
            Console.WriteLine("Done.");
        }

        static void workflowTerminated(object sender,
                                      WorkflowTerminatedEventArgs e)
        {
            Console.WriteLine("Workflow instance terminated, reason: '{0}'.", e.Exception.Message);
            waitHandle.Set();
        }

        static void workflowCompleted(object sender, WorkflowCompletedEventArgs e)
        {
        }

        static void workflowIdled(object sender, WorkflowEventArgs e)
        {
            Console.WriteLine("Workflow instance idled.");
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Monroe Community
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions