很多时候,宿主要与工作流实例的内部对象进行通信,比如启动时,要设定某些属性的值,完成时要读取某些属性的值。 本例中是使用CreateWorkflow(工作流, 参数)的方式,在创建工作流时,对工作流的[年龄]属性赋值。当工作流实例无成后,在OnWorkflowCompleted事件的WorkflowCompletedEventArgs参数中将属性值读出。
1.宿主端写入参数和读出返回的参数
using(WorkflowRuntime runtime = new WorkflowRuntime())

...{
AutoResetEvent waitHandle = new AutoResetEvent(false);

runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) ...{
waitHandle.Set();
Console.WriteLine(e.OutputParameters["Result"].ToString());
};

runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) ...{ waitHandle.Set(); };
runtime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)

...{
Console.WriteLine("Workflow started:" + e.WorkflowInstance.InstanceId);
};
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("Name", "adam");
param.Add("Result", "");
WorkflowInstance instance;
instance = runtime.CreateWorkflow(typeof(BugFlow), param);
instance.Start();

}


2.工作流中读取参数
public sealed partial class BugFlow: SequentialWorkflowActivity

...{
private string _name = "";
public string Name

...{
get

...{
return _name;
}
set

...{
_name = value;
}
}

private string _resule = "";
public string Result

...{

get ...{ return _resule; }

set ...{ _resule = value; }
}
public BugFlow()

...{
InitializeComponent();
}

public BugAddedArgs _newBug = default(Chapter3.BugAddedArgs);

private void Code(object sender, EventArgs e)

...{
Console.WriteLine(this.WorkflowInstanceId.ToString() + ":" + Name);
Result = "Back";
}
}