WF数据跟踪SqlTrackingService的问题
在练习WF的Hands-on Labs\Lab03部分的时候,遇到了一个如下的问题:
代码比较简单:
Code Snippet
- static string connectionString = "Initial Catalog=TrackingStore; " +
- "Data Source=.; " +
- "Integrated Security=SSPI;";
- static void Main(string[] args)
- {
- using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
- {
- workflowRuntime.AddService(new SqlTrackingService(connectionString));
- AutoResetEvent waitHandle = new AutoResetEvent(false);
- workflowRuntime.WorkflowCompleted += delegate(object sender,
- WorkflowCompletedEventArgs e) { waitHandle.Set(); };
- workflowRuntime.WorkflowTerminated += delegate(object sender,
- WorkflowTerminatedEventArgs e)
- {
- Console.WriteLine(e.Exception.Message);
- waitHandle.Set();
- };
- WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof
- (DefaultSQLServices.Workflow1));
- instance.Start();
- instance.Suspend("Reason we are suspending the workflow.");
- instance.Resume();
- waitHandle.WaitOne();
- GetInstanceTrackingEvents(instance.InstanceId);
- Console.WriteLine("Workflow Completed - press ENTER to continue");
- Console.Read();
- }
- }
GetInstanceTrackingEvents()方法代码如下:
Code Snippet
- static void GetInstanceTrackingEvents(Guid instanceId)
- {
- Console.WriteLine("\r\nInstance Tracking Events :");
- SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);
- SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
- sqlTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance);
- try
- {
- foreach (WorkflowTrackingRecord workflowTrackingRecord in sqlTrackingWorkflowInstance.WorkflowEvents)
- {
- Console.WriteLine("EventDescription : {0} DateTime : {1}", workflowTrackingRecord.TrackingWorkflowEvent, workflowTrackingRecord.EventDateTime);
- }
- }
- catch (Exception)
- {
- Console.WriteLine("No Instance Tracking Events Found");
- }
- }
工作流Workflow1的只有一个Code活动,输出一段代码。
我遇到的问题是:在程序执行的时候到waitHandle.WaitOne()这一步,系统线程会停止,然后CPU始终保持在一个90%以上。尝试了很多方案,包括重启,换机器都存在问题,Google了好久也没有满意的答复。只是有一个和我遇到的类似问题的人:http://social.msdn.microsoft.com/Forums/en-US/windowsworkflowfoundation/thread/67ea8ad6-c700-4096-a9c4-164d2e7cf7cb/这里虽然没有给出确切的答复,但是给我提供一个思路:可能就是Hand-On自带的创建数据库的一些sql语句的问题。
解决:
workflow安装的位置C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL有两个文件夹ZH-CHS和EN,我本身是中文操作系统,就把ZH-CHS里面的四个sql命令文件拷贝出来,覆盖掉里面自带的SQL文件(呵呵,覆盖的时候发现文件大小不一样)。然后重新执行Hands-on Labs\Lab03里面的cmd命令,OK,问题解决。
总结:我们在工作过程中,经常会用到别人的现成的东西,甚至老外的。那么如果过程中出现问题,不妨考虑一下是不是语言版本的问题。
努力不一定成功,但放弃一定失败!