调用子流程
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.
?異步,而且還沒回調,異步我要你干嗎。
?看一下這個例子吧,用了一個多線程常用的方式解決了調用子流程的問題,看這個例子注意以下幾點:
1.不用InvokeWorkflowActivity也能實現調用子流程
2.這個例子的中心思想不是如何用InvokeWorkflowActivity調用子流程,我有N多比這簡單的方法,這個例子的主要演示了如何將工作流的業務處理封裝到自定義引擎中?
調用子流程思路如下
本例是通過重寫WorkflowRuntime實現,也就是說以上活動沒在在宿主中實現,全過程對宿主來說是一個黑盒
????{
?????
????????//外部事件
????????[Serializable()]
????????public?class?事件標志?:?System.Workflow.Activities.ExternalDataEventArgs
????{
????????private?Guid?實例GUID_存值;
????????public?string?自定義存值;
????????public?事件標志(Guid?instanceId)
????????????:?base(instanceId)
????????{
????????????this.實例GUID_存值?=?instanceId;
????????}
????????public?Guid?實例GUID
????????{
????????????get?{?return?this.實例GUID_存值;?}
????????????set?{?this.實例GUID_存值?=?value;?}
????????}
????}
???????
????????[System.Workflow.Activities.ExternalDataExchange()]
????????public?interface?外部事件映射接口
????????{
????????????event?System.EventHandler<事件標志>?子流程完成事件;
????????}
????????
????????public?class?功能類_外部事件?:?外部事件映射接口
????????{
????????????public?event?EventHandler<事件標志>?子流程完成事件;
????????????public?void?觸發子流程完成事件(object?sender,?Guid?id,?string?自定義存值)
????????????{
????????????????事件標志?e?=?new?事件標志(id);
????????????????e.自定義存值?=?自定義存值;
????????????????子流程完成事件(sender,?e);
????????????}
????????}
????????//外部方法
????????[System.Workflow.Activities.ExternalDataExchange()]
????????public?interface?外部方法映射接口
????????{?void?子流程完成(string?所屬父流程ID,?string?流程ID);}
???
????????public?class?功能類_外部方法?:?外部方法映射接口
????????{
????????????public?string?父流程ID=null;
????????????public?string?當前流程ID?=?null;
????????????public?void?子流程完成(string?所屬父流程ID,?string?流程ID)
????????????{
????????????????當前流程ID?=?流程ID;
????????????????父流程ID?=?所屬父流程ID;
????????????????Console.WriteLine("方法已被觸發");
????????????}
???
????????}
????????//改寫引擎
????????public?class?自定義工作流引擎?:?System.Workflow.Runtime.WorkflowRuntime
????????{
????????????System.Workflow.Activities.ExternalDataExchangeService?外部數據通信服務;
????????????功能類_外部事件?外事=new?功能類_外部事件();
????????????功能類_外部方法?外方=new?功能類_外部方法();
????????????public?自定義工作流引擎()
????????????????:base()
????????????{
????????????????外部數據通信服務?=?new?System.Workflow.Activities.ExternalDataExchangeService();
????????????????test.宿主("自定義引擎中",?"準備向引擎添加外部數據通信服務");
????????????????this.AddService(外部數據通信服務);
????????????????外部數據通信服務.AddService(外事);
????????????????外部數據通信服務.AddService(外方);
????????????????this.WorkflowCompleted?+=?new?EventHandler<System.Workflow.Runtime.WorkflowCompletedEventArgs>(自定義工作流引擎_WorkflowCompleted);
????????????}
????????????void?自定義工作流引擎_WorkflowCompleted(object?sender,?System.Workflow.Runtime.WorkflowCompletedEventArgs?e)
????????????{
??????????
????????????????if?(外方.父流程ID?!=null?)
????????????????{
????????????????????Console.WriteLine("內部完成事件:觸發:子流程完成事件");
????????????????????外事.觸發子流程完成事件("wxd",new?Guid(外方.父流程ID),"wxwinter");
????????????????????外方.父流程ID?=?null;
????????????????}
????????????????Console.WriteLine("內部完成事件:工作流完成");
????????????}
????????????
????????????
????????}
????????
}
例子 WWF調試模板(子流程).rar
?
轉載于:https://www.cnblogs.com/foundation/archive/2006/10/25/540033.html
總結
- 上一篇: 图说Fourier变换
- 下一篇: cad批量打印快捷键_原来CAD还能这么