Windows services 从Windows服务调用工作流时出现问题。。卡在waitHandle.WaitOne()上;
请查看下面的代码Windows services 从Windows服务调用工作流时出现问题。。卡在waitHandle.WaitOne()上;,windows-services,workflow-foundation,Windows Services,Workflow Foundation,请查看下面的代码 using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.ServiceProcess; using System.Threading; using System.Workflow.Runtime; namespace TestWinService { public partial class TestWorkflowS
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Threading;
using System.Workflow.Runtime;
namespace TestWinService
{
public partial class TestWorkflowService : ServiceBase
{
StreamWriter sw;
Dictionary<string, object> dict = new Dictionary<string, object>();
WorkflowRuntime workflowRuntime;
AutoResetEvent waitHandle = new AutoResetEvent(false);
public TestWorkflowService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Debugger.Launch();
sw = new StreamWriter(@"D:\newFileForTest.txt", true);
dict.Add("OperationType", "+");
dict.Add("Num1", 10);
dict.Add("Num2", 20);
workflowRuntime = new WorkflowRuntime();
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1), dict);
instance.Start();
sw.WriteLine("Workflow Instance started at : " + DateTime.Now);
waitHandle.WaitOne(); // STUCK HERE.. Control is not moving at all
sw.Write("waitHandle.WaitOne() passed");
}
protected override void OnStop()
{
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
sw.WriteLine("The result is : " + e.OutputParameters["Result"]);
sw.Write("Service stopped at : " + DateTime.Now);
waitHandle.Set();
};
sw.Close();
}
}
}
一个调用工作流的简单窗口服务,但它被困在waitHandle.WaitOne
在控制台应用程序中同样可以正常运行。我是否遗漏了一些东西,或者有不同的方法来做到这一点。。请帮忙
提前感谢您没有连接设置等待句柄的工作流事件,直到您的OnStop方法。我假设的工作流正在运行,正常吗?它只是在完成,而从不设置等待句柄,因为您还没有完成事件的侦听器。创建工作流运行时后立即连接事件