Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Microsoft Windows Workflow Foundation

, 31 Aug 2009 CPOL
An artilce that explains how to call external data and methods.
MVDataChecker_Completed.zip
MVDataChecker Completed
_UpgradeReport_Files
UpgradeReport_Minus.gif
UpgradeReport_Plus.gif
Backup
MVDataChecker
Properties
MVDataService
Properties
MVWorkflow
Properties
DataSources
Workflow1.datasource
Settings.settings
MVDataChecker
bin
Debug
MVDataChecker.exe
MVDataChecker.vshost.exe
MVDataChecker.vshost.exe.manifest
MVDataService.dll
MVWorkflow.dll
Release
MVDataChecker.exe
MVDataChecker.vshost.exe
MVDataService.dll
MVWorkflow.dll
obj
Debug
MVDataChecker.exe
TempPE
Properties.Resources.Designer.cs.dll
Properties
MVDataService
bin
Debug
MVDataService.dll
obj
Debug
MVDataService.dll
TempPE
Properties
MVWorkflow
bin
Debug
MVDataService.dll
MVWorkflow.dll
obj
Debug
MVWorkflow.dll
TempPE
Properties
DataSources
Workflow1.datasource
Settings.settings
WorkflowInvoker
WorkflowInvoker
Properties
WorkflowInvoker Completed
Workflow1
Properties
Settings.settings
Workflow2
Properties
Settings.settings
WorkflowInvoker
bin
Release
Workflow1.dll
Workflow2.dll
WorkflowInvoker.exe
WorkflowInvoker.vshost.exe
Properties
MVDataChecker
MVDataChecker
Properties
MVDataService
Properties
MVWorkflow
Properties
DataSources
Workflow1.datasource
Settings.settings
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)

Share

About the Author

logicchild
Other Pref. Trust
United States United States
I started electronics training at age 33. I began studying microprocessor technology in an RF communications oriented program. I am 43 years old now. I have studied C code, opcode (mainly x86 and AT+T) for around 3 years in order to learn how to recognize viral code and the use of procedural languages. I am currently learning C# and the other virtual runtime system languages. I guess I started with the egg rather than the chicken. My past work would indicate that my primary strength is in applied mathematics.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 31 Aug 2009
Article Copyright 2009 by logicchild
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid