[英]How to invoke a method from a workflow in WF 4?
I would like to invoke a simple method (no arguments, returns void) from within a workflow. 我想从工作流程中调用一个简单的方法(无参数,返回void)。 Suppose I have the following class:
假设我有以下课程:
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.");
}
}
How do I call ReusableMethod
from within my workflow? 如何在工作流程中调用
ReusableMethod
? I was looking at InvokeAction
but that doesn't seem to be what I want. 我当时在看
InvokeAction
但这似乎不是我想要的。 I could also write a custom activity that calls this method, but I'm specifically interested in this scenario. 我也可以编写一个调用此方法的自定义活动,但是我对此场景特别感兴趣。 Is this possible?
这可能吗?
How about InvokeMethod ? 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.