[英]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.