1.新建一个代码活动 BookMarkActivity
2.修改为继承自NativeActivity
3.重写 CanInduceIdle 属性 返回true
4.修改Excute方法的参数
5.在方法内部 创建书签 参数为 (书签名,回调函数)
1 public sealed class BookMarkActivity : NativeActivity 2 { 3 // 定义一个int类型的活动输出参数 4 // public InArgument<string> Text { get; set; } 5 public OutArgument<int> OutNum { get; set; }
6 protected override bool CanInduceIdle 7 { 8 get 9 { 10 return true; 11 } 12 } 13 14 // 如果活动返回值,则从 CodeActivity<TResult> 15 // 派生并从 Execute 方法返回该值。 16 protected override void Execute(NativeActivityContext context) 17 { 18 //创建书签 指定回调函数 19 context.CreateBookmark("demo", new BookmarkCallback(SetBookmarkValue)); 20 // 获取 Text 输入参数的运行时值 21 //string text = context.GetValue(this.Text); 22 } 23 //设值书签 的回调函数 24 public void SetBookmarkValue(NativeActivityContext context,Bookmark mark,object value) 25 { 26 //设值 27 context.SetValue(OutNum,(int)value); 28 } 29 }
6.给回调函数传递value值
WFDemoActivity为需要运行的工作流
1 WorkflowApplication wfApp = new WorkflowApplication(new WFDemoActivity()); 2 3 private void btnStartWF_Click(object sender, EventArgs e) 4 { 5 wfApp.Idle += a => 6 { 7 Console.WriteLine("工作流停下来了..."); 8 }; 9 10 //WorkflowInvoker.Invoke(new WFDemoActivity()); 11 //开始运行工作流 12 wfApp.Run(); 13 } 14 15 private void btnContinue_Click(object sender, EventArgs e) 16 { 17 //给'demo'书签 传入参数value 18 wfApp.ResumeBookmark("demo",int.Parse(this.txtNum.Text)); 19 }
缺点:不能做到工作流的持久性(序列化)