zoukankan      html  css  js  c++  java
  • 工作流学习笔记给工作流传递参数

    C#->控制台顺序工作流->拖放code->双击生成事件处理程序

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Linq;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;
    
    namespace WorkflowConsoleApplication1
    {
    	public sealed partial class Workflow1: SequentialWorkflowActivity
    	{
            public string MyName { get; set; }
    
            public int MyID { get; set; }
    		public Workflow1()
    		{
    			InitializeComponent();
    		}
    
            private void codeActivity1_ExecuteCode(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(600);
                Console.WriteLine("My ID Is :{0}", this.MyID);            
                Console.WriteLine("My Name Is :{0}", this.MyName);            
            }
    	}
    
    }
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Workflow.Runtime;
    using System.Workflow.Runtime.Hosting;
    
    namespace WorkflowConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    AutoResetEvent waitHandle = new AutoResetEvent(false);
                    //工作流完成时触发
                    workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) 
                    {
                        //通知waitHandle,释放控制台应用程序
                        waitHandle.Set();
                    };
                    //工作流发生错误时触发
                    workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };
    
                    //构造参数
                    Dictionary<string, object> wf_args = new Dictionary<string, object>();
                    wf_args.Add("MyID", 1);
                    wf_args.Add("MyName", "allen");
    
                    //创建工作流的实例并启动工作流
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1), wf_args);
                    instance.Start();
    
                    //让控制台等待工作流的完成
                    waitHandle.WaitOne();
    
                    Console.ReadKey();
                }
            }
        }
    }
    
    
  • 相关阅读:
    XAML学习笔记之Layout(五)——ViewBox
    XAML学习笔记——Layout(三)
    XAML学习笔记——Layout(二)
    XAML学习笔记——Layout(一)
    从0开始搭建SQL Server 2012 AlwaysOn 第三篇(安装数据,配置AlwaysOn)
    从0开始搭建SQL Server 2012 AlwaysOn 第二篇(配置故障转移集群)
    从0开始搭建SQL Server 2012 AlwaysOn 第一篇(AD域与DNS)
    Sql Server 2012 事务复制遇到的问题及解决方式
    Sql Server 2008R2升级 Sql Server 2012 问题
    第一次ACM
  • 原文地址:https://www.cnblogs.com/liulun/p/1674960.html
Copyright © 2011-2022 走看看