gpt4 book ai didi

c# - 如何从 WF 4 中的工作流调用方法?

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:48 24 4
gpt4 key购买 nike

我想从工作流中调用一个简单的方法(无参数,返回无效)。假设我有以下类(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.");
}
}

如何从我的工作流中调用 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.");
}
}

关于c# - 如何从 WF 4 中的工作流调用方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3503184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com