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的块级标签、内联标签
    【JS跨域取XML】之——借助AS的URLLoader
    【前端重构技能天赋】(二)——Javascript、CSS篇
    【IE大叔的嘴歪眼斜】之—— 由hasLayout引发的临床CSS Bug表
    【F12一下,看看页面里的第一行】——说说浏览器兼容性模式
    【IE大叔的杀马特审美】之——CSS盒子模型
    【前端重构技能天赋】(一)——内容篇
    【总有一些东西要弄清】——说说面试时一系列的CSS问题
    【拆了CSS照样是页面】之——HTML语义化(含H5)
    【javascript继承】之——原型链继承和类式继承
  • 原文地址:https://www.cnblogs.com/volnet/p/931843.html
Copyright © 2011-2022 走看看