簡體   English   中英

如何從WF 4中的工作流程中調用方法?

[英]How to invoke a method from a workflow in WF 4?

我想從工作流程中調用一個簡單的方法(無參數,返回void)。 假設我有以下課程:

public class TestClass
{
    public void StartWorkflow()
    {
        var workflow = new Sequence
        {
            Activities =
            {
                new WriteLine { Text = "Before calling method." },
                // Here I would like to call the method ReusableMethod().
                new WriteLine { Text = "After calling method." }
            }
        }
        new WorkflowApplication(workflow).Run();
    }

    public void ReusableMethod()
    {
        Console.WriteLine("Inside method.");
    }
}

如何在工作流程中調用ReusableMethod 我當時在看InvokeAction但這似乎不是我想要的。 我也可以編寫一個調用此方法的自定義活動,但是我對此場景特別感興趣。 這可能嗎?

InvokeMethod怎么

public class TestClass
{
    public void StartWorkflow()
    {
        var workflow = new Sequence
                        {
                            Activities =
                                {
                                    new WriteLine {Text = "Before calling method."},
                                    // Here I would like to call the method ReusableMethod().
                                    new InvokeMethod {MethodName="ReusableMethod", TargetType = typeof(TestClass)},
                                    new WriteLine {Text = "After calling method."}
                                }
                        };
        var wf = new WorkflowApplication(workflow);
        wf.Run();
        var are = new AutoResetEvent(false);
        wf.Completed = new Action<WorkflowApplicationCompletedEventArgs>(arg => are.Set());
        are.WaitOne(5000);
    }

    public static void ReusableMethod()
    {
        Console.WriteLine("Inside method.");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM