浅析 在宿主中使用参数与实例通信

转载

本文用C#浅析,用中文做名称为了练习用,实际开发不允许

 

工作流代码
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;
using System.Windows.Forms;

namespace WorkflowLibrary1
{
    
public sealed partial class Workflow1 : SequentialWorkflowActivity
    
{
        
public Workflow1()
        
{
            InitializeComponent();
        }


        
//------------------------年龄属性----------------------------------
        private int 年龄_value;
        
public int 年龄
        
{
            
set
            
{
                年龄_value 
= value;
            }

            
get
            
{
                
return 年龄_value;
            }

        }


        
public enum 年龄状况
        
{
            成年,
            未成年,
        }


        
//------------------------年龄类型属性------------------------------
        private 年龄状况 年龄类型_value;
        
public 年龄状况 年龄类型
        
{
            
set
            
{
                年龄类型_value 
= value;
            }

            
get
            
{
                
return 年龄类型_value;
            }

        }



        
//------------------IfElse的两个分支----------------------
        private void code_t_code(object sender, EventArgs e)
        
{
            
//  >=18岁的
            年龄类型 = 年龄状况.成年;
            MessageBox.Show(
"年龄>=18的代码块,年龄:" + this.年龄.ToString());
        }


        
private void code_f_code(object sender, EventArgs e)
        
{
            
//  <18岁的
            年龄类型 = 年龄状况.未成年;
            MessageBox.Show(
"年龄<18的代码块,年龄:" + this.年龄.ToString());
        }

    }

}


 

 

我用的是窗体的,textBox1为输入的年龄文本框,按钮为“测试年龄段

 

宿主程序代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Activities;

namespace WorkflowMonitorManagermentStudio
{
    
public partial class Form1 : Form
    
{
        
private WorkflowRuntime runtime = null;

        
private WorkflowInstance instance = null;

        
private static AutoResetEvent WaitHandle = new AutoResetEvent(false);

        
public Form1()
        
{
            InitializeComponent();

            runtime 
= new WorkflowRuntime();

            runtime.StartRuntime();

            runtime.WorkflowCompleted 
+= new EventHandler<WorkflowCompletedEventArgs>(runtime_WorkflowCompleted);
            runtime.WorkflowTerminated 
+= new EventHandler<WorkflowTerminatedEventArgs>(runtime_WorkflowTerminated);
        }


        
void runtime_WorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
        
{
            MessageBox.Show(e.Exception.Message.ToString());
            WaitHandle.Set();
        }


        
void runtime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
        
{
            
string value = e.OutputParameters["年龄类型"].ToString();
            MessageBox.Show(
"年龄类型:" + value.ToString());
            MessageBox.Show(
"年龄:" + e.OutputParameters["年龄"].ToString());
            WaitHandle.Set();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            
if (textBox1.Text.Trim() == "")
            
{
                MessageBox.Show(
"请输入年龄");
                
return;
            }

            
else
            
{
                Dictionary
<stringobject> 参数 = new Dictionary<stringobject>();

                参数.Add(
"年龄", Int32.Parse(textBox1.Text.Trim()));

                instance 
= runtime.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1), 参数);

                instance.Start();
            }

        }

    }

}


 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值