请原谅我,如果我的问题看起来很愚蠢,但我对Workflow完全不熟悉。我想要做的是:我在Workflow Foundation项目中有一些数据库命中,有些在ASP.NET应用程序中。我想要实现的是在同一事务中在Workflow foundation和ASP.NET中执行数据库操作。告诉我有可能吗?我正在使用linq2sql。
这是我的代码:
using(var context = new MyDBContext())
{
context.Transaction = context.Connection.BeginTransaction();
//Here I am calling my Workflow function
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
waitHandle.Set();
if ((string)e.OutputParameters["OutputMessage"] != "")
msg = "Workflow error : " + (string)e.OutputParameters["OutputMessage"];
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine("ERROR: " + e.Exception.Message);
waitHandle.Set();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(MyWorkflow), parameters);
instance.Start();
waitHandle.WaitOne();
}
//DB Operation in ASP.NET
context.DbOperation();
context.SubmitChanges();
context.Transaction.Commit();
}
答案 0 :(得分:1)
我不这么认为。 instance.Start()
立即返回。实际的工作流活动将在不同的线程中运行(并且可能在不同的进程或不同的机器中)。您必须在工作流程中管理交易。