zoukankan      html  css  js  c++  java
  • 有返回值的Bookmark

    首先代码创建Activity:

     public sealed class WaitForResponse<TResult>:NativeActivity<TResult>
        {
            public WaitForResponse()
                :base()
            {}
    
            public string ResponseName { get; set; }
    
            protected override bool CanInduceIdle => true;
    
            protected override void Execute(NativeActivityContext context)
            {
                context.CreateBookmark(this.ResponseName, new BookmarkCallback(this.ReceivedResponse)); //这里加入BookmarkCallback, 用来设置返回值
            }
    
            void ReceivedResponse(NativeActivityContext context,Bookmark bookmark,object obj)
            {
                this.Result.Set(context, (TResult)obj);
            }
        }

    创建Workflow:

    在Branch1中创建一个变量myVar, 然后在创建的Activity中设置Result为myVar, 这个myVar会接收这个Activity创建Bookmark时返回的值. 

    测试:

    public partial class Form1 : Form
        {
            static WorkflowApplication wfapp;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                wfapp = new WorkflowApplication(new ActivityLibrary1.Activity1());
                wfapp.Idle = MyIdle;
                wfapp.Run();
    
                ThreadPool.QueueUserWorkItem(ReadName); //传入的关键, 不然workflow不会resume, Pick会运行到Branch2中去
            }
    
            void MyIdle(WorkflowApplicationIdleEventArgs e)
            {
                Console.WriteLine("Idle:" + e.InstanceId);
            }
    
            static void ReadName(object state)
            {
                string text = "abc";
    
                // Resume the Activity that set this bookmark (ReadString).
               Form1.wfapp.ResumeBookmark("P1", text);         
               
            }
        }
  • 相关阅读:
    信号量Semaphore
    进程锁Lock
    创建多进程Process
    什么是进程?什么是线程?进程和线程之间的区别是什么?
    Git命令
    xss攻击问题以及如何防范
    ORM跨表查询问题
    for循环将字典添加到列表中出现覆盖前面数据的问题
    Linux源码的目录结构
    嵌入式中 MMU的功能
  • 原文地址:https://www.cnblogs.com/hzb2001/p/9066667.html
Copyright © 2011-2022 走看看