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();
                }
            }
        }
    }
    
    
  • 相关阅读:
    Makefile学习
    Tmux使用
    Linux进程管理学习资料
    Linux内存管理学习资料
    Python常用的软件包
    Docker 学习
    Intel处理器技术文档
    Firefly-RK3399笔记
    Linux Kernel API
    ARM 技术文档
  • 原文地址:https://www.cnblogs.com/liulun/p/1674960.html
Copyright © 2011-2022 走看看