Click here to Skip to main content
15,886,075 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.3K   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.Workflow.Runtime.Hosting;

namespace MVDataChecker
{
    public static class WorkflowFactory
    {
        // Singleton instance of the workflow runtime
        private static WorkflowRuntime _workflowRuntime = null;

        // Lock (sync) object
        private static object _syncRoot = new object();

        // Factory method
        public static WorkflowRuntime GetWorkflowRuntime()
        {
            // Lock execution thread in case of multi-threaded
            // (concurrent) access.
            lock (_syncRoot)
            {
                // Check for startup condition
                if (null == _workflowRuntime)
                {
                    // Provide for shutdown
                    AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkflowRuntime);
                    AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkflowRuntime);

                    // Not started, so create instance
                    _workflowRuntime = new WorkflowRuntime();

                    // Start the runtime
                    _workflowRuntime.StartRuntime();
                } // if

                // Return singleton instance
                return _workflowRuntime;
            } // lock
        }

        // Shutdown method
        static void StopWorkflowRuntime(object sender, EventArgs e)
        {
            if (_workflowRuntime != null)
            {
                if (_workflowRuntime.IsStarted)
                {
                    try
                    {
                        // Stop the runtime
                        _workflowRuntime.StopRuntime();
                    }
                    catch (ObjectDisposedException)
                    {
                        // Already disposed of, so ignore...
                    } // catch
                } // if
            } // if
        }
    }
}

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