调用子流程
Asynchronously runs one workflow from another. This class cannot be inherited.
InvokeWorkflowActivity then creates and invokes a workflow instance of the specified type, passing the parameters that have been provided. As soon as the workflow has been invoked, the InvokeWorkflowActivity finishes immediately.
Use the InvokeWorkflowActivity to start one workflow from another. The InvokeWorkflowActivity completes before the launched workflow starts executing and the next activity in the workflow branch is executed.
?異步,而且還沒回調(diào),異步我要你干嗎。
?看一下這個例子吧,用了一個多線程常用的方式解決了調(diào)用子流程的問題,看這個例子注意以下幾點(diǎn):
1.不用InvokeWorkflowActivity也能實(shí)現(xiàn)調(diào)用子流程
2.這個例子的中心思想不是如何用InvokeWorkflowActivity調(diào)用子流程,我有N多比這簡單的方法,這個例子的主要演示了如何將工作流的業(yè)務(wù)處理封裝到自定義引擎中?
調(diào)用子流程思路如下
本例是通過重寫WorkflowRuntime實(shí)現(xiàn),也就是說以上活動沒在在宿主中實(shí)現(xiàn),全過程對宿主來說是一個黑盒
????{
?????
????????//外部事件
????????[Serializable()]
????????public?class?事件標(biāo)志?:?System.Workflow.Activities.ExternalDataEventArgs
????{
????????private?Guid?實(shí)例GUID_存值;
????????public?string?自定義存值;
????????public?事件標(biāo)志(Guid?instanceId)
????????????:?base(instanceId)
????????{
????????????this.實(shí)例GUID_存值?=?instanceId;
????????}
????????public?Guid?實(shí)例GUID
????????{
????????????get?{?return?this.實(shí)例GUID_存值;?}
????????????set?{?this.實(shí)例GUID_存值?=?value;?}
????????}
????}
???????
????????[System.Workflow.Activities.ExternalDataExchange()]
????????public?interface?外部事件映射接口
????????{
????????????event?System.EventHandler<事件標(biāo)志>?子流程完成事件;
????????}
????????
????????public?class?功能類_外部事件?:?外部事件映射接口
????????{
????????????public?event?EventHandler<事件標(biāo)志>?子流程完成事件;
????????????public?void?觸發(fā)子流程完成事件(object?sender,?Guid?id,?string?自定義存值)
????????????{
????????????????事件標(biāo)志?e?=?new?事件標(biāo)志(id);
????????????????e.自定義存值?=?自定義存值;
????????????????子流程完成事件(sender,?e);
????????????}
????????}
????????//外部方法
????????[System.Workflow.Activities.ExternalDataExchange()]
????????public?interface?外部方法映射接口
????????{?void?子流程完成(string?所屬父流程ID,?string?流程ID);}
???
????????public?class?功能類_外部方法?:?外部方法映射接口
????????{
????????????public?string?父流程ID=null;
????????????public?string?當(dāng)前流程ID?=?null;
????????????public?void?子流程完成(string?所屬父流程ID,?string?流程ID)
????????????{
????????????????當(dāng)前流程ID?=?流程ID;
????????????????父流程ID?=?所屬父流程ID;
????????????????Console.WriteLine("方法已被觸發(fā)");
????????????}
???
????????}
????????//改寫引擎
????????public?class?自定義工作流引擎?:?System.Workflow.Runtime.WorkflowRuntime
????????{
????????????System.Workflow.Activities.ExternalDataExchangeService?外部數(shù)據(jù)通信服務(wù);
????????????功能類_外部事件?外事=new?功能類_外部事件();
????????????功能類_外部方法?外方=new?功能類_外部方法();
????????????public?自定義工作流引擎()
????????????????:base()
????????????{
????????????????外部數(shù)據(jù)通信服務(wù)?=?new?System.Workflow.Activities.ExternalDataExchangeService();
????????????????test.宿主("自定義引擎中",?"準(zhǔn)備向引擎添加外部數(shù)據(jù)通信服務(wù)");
????????????????this.AddService(外部數(shù)據(jù)通信服務(wù));
????????????????外部數(shù)據(jù)通信服務(wù).AddService(外事);
????????????????外部數(shù)據(jù)通信服務(wù).AddService(外方);
????????????????this.WorkflowCompleted?+=?new?EventHandler<System.Workflow.Runtime.WorkflowCompletedEventArgs>(自定義工作流引擎_WorkflowCompleted);
????????????}
????????????void?自定義工作流引擎_WorkflowCompleted(object?sender,?System.Workflow.Runtime.WorkflowCompletedEventArgs?e)
????????????{
??????????
????????????????if?(外方.父流程ID?!=null?)
????????????????{
????????????????????Console.WriteLine("內(nèi)部完成事件:觸發(fā):子流程完成事件");
????????????????????外事.觸發(fā)子流程完成事件("wxd",new?Guid(外方.父流程ID),"wxwinter");
????????????????????外方.父流程ID?=?null;
????????????????}
????????????????Console.WriteLine("內(nèi)部完成事件:工作流完成");
????????????}
????????????
????????????
????????}
????????
}
例子 WWF調(diào)試模板(子流程).rar
?
轉(zhuǎn)載于:https://www.cnblogs.com/foundation/archive/2006/10/25/540033.html
總結(jié)
- 上一篇: 图说Fourier变换
- 下一篇: cad批量打印快捷键_原来CAD还能这么