zoukankan      html  css  js  c++  java
  • 【代码保留】WorkflowRuntimeFactory

    由于工作流运行时WorkflowRuntime在一个应用程序域中只允许存在一个实例,因此可以用单件Singleton模式来限制,并可以用工厂模式来调用,另者由于运行时需要有Start和Stop,因此也可以在工厂内添加相应的方法来启动和关闭WorkflowRuntime.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Workflow.Runtime;

    namespace WorkflowHost
    {
        
    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
            }
        }
    }
  • 相关阅读:
    帝国 标签模板 使用程序代码 去除html标记 并 截取字符串
    iis6 伪静态 iis配置方法 【图解】
    您来自的链接不存在 帝国CMS
    帝国cms Warning: Cannot modify header information headers already sent by...错误【解决方法】
    .fr域名注册 51元注册.fr域名
    帝国网站管理系统 恢复栏目目录 建立目录不成功!请检查目录权限 Godaddy Windows 主机
    星外虚拟主机管理平台 开通数据库 出现Microsoft OLE DB Provider for SQL Server 错误 '8004' 从字符串向 datetime 转换失败
    ASP.NET 自定义控件学习研究
    CSS层叠样式表之CSS解析机制的优先级
    ASP.NET程序员工作面试网络收藏夹
  • 原文地址:https://www.cnblogs.com/volnet/p/931843.html
Copyright © 2011-2022 走看看