我试图让 StateMachine 在状态之间执行一些数据库操作。
所以我有一个“开始”状态,它使用 CallExternalMethodActivity 在一个用 ExternalDataExchangeAttribute 修饰的类上调用“BeginExecuteNonQuery”函数。之后,它使用 SetStateActivity 更改为“结束”状态。
“结束”状态使用 HandleExternalEventActivity 来监听“EndExecuteNonQuery”事件。
我可以单步执行本地服务,进入“BeginExecuteNonQuery”函数。
问题是“EndExecuteNonQuery”为空。
public class FailoverWorkflowController : IFailoverWorkflowController
{
private readonly WorkflowRuntime workflowRuntime;
private readonly FailoverWorkflowControlService failoverWorkflowControlService;
private readonly DatabaseControlService databaseControlService;
public FailoverWorkflowController()
{
workflowRuntime = new WorkflowRuntime();
workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;
ExternalDataExchangeService dataExchangeService = new ExternalDataExchangeService();
workflowRuntime.AddService(dataExchangeService);
databaseControlService = new DatabaseControlService();
workflowRuntime.AddService(databaseControlService);
workflowRuntime.StartRuntime();
}
...
}
...
public void BeginExecuteNonQuery(string command)
{
Guid workflowInstanceID = WorkflowEnvironment.WorkflowInstanceId;
ThreadPool.QueueUserWorkItem(delegate(object state)
{
try
{
int result = ExecuteNonQuery((string)state);
EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, result));
}
catch (Exception exception)
{
EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, exception));
}
}, command);
}
我的实施做错了什么?
-斯坦