大家好,我写WWF时遇到下面这个问题,请教下CSDN上的朋友们.我做的是个顺序工作流的例子。就简单的一个code输出一行提示文字。
现在在控制台应用程序中加载这个工作流时,代码如下:
static void Main(string[] args)
{
//WorkflowRuntime workflowRuntime = new WorkflowRuntime();
string connectionString = "Initial Catalog=TrackingStore;Data Source=chenxiuping\\SQLEXPRESS;Integrated Security=SSPI;";
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
System.Workflow.Runtime.Tracking.SqlTrackingService sqlTrackingService = new System.Workflow.Runtime.Tracking.SqlTrackingService(connectionString);
workflowRuntime.AddService(sqlTrackingService);
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();
};
workflowRuntime.Started += new EventHandler<WorkflowRuntimeEventArgs>(workflowRuntime_Started);
workflowRuntime.Stopped += new EventHandler<WorkflowRuntimeEventArgs>(workflowRuntime_Stopped);
workflowRuntime.WorkflowResumed += new EventHandler<WorkflowEventArgs>(workflowRuntime_WorkflowResumed);
workflowRuntime.WorkflowSuspended += new EventHandler<WorkflowSuspendedEventArgs>(workflowRuntime_WorkflowSuspended);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(HostingWorkflowRuntime.SimpleWorkflow));
instance.Start();
instance.Suspend("暂停提示信息。");//暂停进程
instance.Resume();//继续进程 waitHandle.WaitOne();
Console.WriteLine("Workflow Completed - press ENTER to continue");
Console.Read();
}
==================
现在问题是,添加了这句 workflowRuntime.AddService(sqlTrackingService); 工作流走到倒数第四行的waitHandle.WaitOne(); 就不走了。无法完成这个应用程序。若是注释了这行,不使用这个服务,则可以完成这个应用程序。
想请教大家,这个是怎么回事,该如何修改。
给我个修改的方向也好。谢谢大家了。我是希望这个跟踪服务能记录我的工作流所做的更改,记录这个工作流已经执行到哪一步了。
现在在控制台应用程序中加载这个工作流时,代码如下:
static void Main(string[] args)
{
//WorkflowRuntime workflowRuntime = new WorkflowRuntime();
string connectionString = "Initial Catalog=TrackingStore;Data Source=chenxiuping\\SQLEXPRESS;Integrated Security=SSPI;";
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
System.Workflow.Runtime.Tracking.SqlTrackingService sqlTrackingService = new System.Workflow.Runtime.Tracking.SqlTrackingService(connectionString);
workflowRuntime.AddService(sqlTrackingService);
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();
};
workflowRuntime.Started += new EventHandler<WorkflowRuntimeEventArgs>(workflowRuntime_Started);
workflowRuntime.Stopped += new EventHandler<WorkflowRuntimeEventArgs>(workflowRuntime_Stopped);
workflowRuntime.WorkflowResumed += new EventHandler<WorkflowEventArgs>(workflowRuntime_WorkflowResumed);
workflowRuntime.WorkflowSuspended += new EventHandler<WorkflowSuspendedEventArgs>(workflowRuntime_WorkflowSuspended);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(HostingWorkflowRuntime.SimpleWorkflow));
instance.Start();
instance.Suspend("暂停提示信息。");//暂停进程
instance.Resume();//继续进程 waitHandle.WaitOne();
Console.WriteLine("Workflow Completed - press ENTER to continue");
Console.Read();
}
==================
现在问题是,添加了这句 workflowRuntime.AddService(sqlTrackingService); 工作流走到倒数第四行的waitHandle.WaitOne(); 就不走了。无法完成这个应用程序。若是注释了这行,不使用这个服务,则可以完成这个应用程序。
想请教大家,这个是怎么回事,该如何修改。
给我个修改的方向也好。谢谢大家了。我是希望这个跟踪服务能记录我的工作流所做的更改,记录这个工作流已经执行到哪一步了。
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(HostingWorkflowRuntime.SimpleWorkflow));
这行代码是走不下去的。所以我确认这个连接数据库的字符串是正确的。
至于其中的表。我是根据WWF自带的脚本生成的。我开数据库进去.表都在。也都可以打开。但是里头都没数据.
private static WorkflowRuntime _workflowRuntime = null;
private static object _syncRoot = new object();
private static KACreationServices kas = new KACreationServices();
public static KACreationServices KAS
{
get { return kas; }
}
static WorkFlowHosting()
{
lock (_syncRoot)
{
if (null == _workflowRuntime)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkFlowRuntime);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkFlowRuntime);
_workflowRuntime = new WorkflowRuntime();
_workflowRuntime.WorkflowCreated += new EventHandler<WorkflowEventArgs>(_workflowRuntime_WorkflowCreated);
_workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(_workflowRuntime_WorkflowCompleted);
_workflowRuntime.ServicesExceptionNotHandled += new EventHandler<ServicesExceptionNotHandledEventArgs>(_workflowRuntime_ServicesExceptionNotHandled);
_workflowRuntime.WorkflowAborted += new EventHandler<WorkflowEventArgs>(_workflowRuntime_WorkflowAborted);
SqlTrackingService ts = new SqlTrackingService(KAConfiguration.ConnectionString);//跟踪服务
_workflowRuntime.AddService(ts);
SqlWorkflowPersistenceService ps = new SqlWorkflowPersistenceService(KAConfiguration.ConnectionString, true,
new TimeSpan(1, 0, 0), new TimeSpan(1, 0, 0)); //持久话服务
_workflowRuntime.AddService(ps);
ExternalDataExchangeService kaserverices = new ExternalDataExchangeService();
_workflowRuntime.AddService(kaserverices);
kaserverices.AddService(kas);
//_workflowRuntime.AddService(ss);
SharedConnectionWorkflowCommitWorkBatchService sc = new SharedConnectionWorkflowCommitWorkBatchService(KAConfiguration.ConnectionString);//事务服务
_workflowRuntime.AddService(sc);
_workflowRuntime.StartRuntime();
}
}
}
其中。我修改过你的代码。把 KACreationServices 相关的删除了。你这个是提供数据库连接字符串的吧?
我是直接用一个变量了。 下面是现在的代码。整个Program.cs都贴出来。。
=============================================================================#region Using directivesusing System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Workflow.Runtime.Tracking;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;#endregionnamespace DefaultSQLServices
{
class Program
{
static string connectionString = "Initial Catalog=TrackingStore;" +
"Data Source=CHENXIUPING\\SQLEXPRESS; Integrated Security=SSPI;";
private static WorkflowRuntime _workflowRuntime = null;
private static object _syncRoot = new object();
static void Main(string[] args)
{
lock (_syncRoot)
{
if (null == _workflowRuntime)
{
_workflowRuntime = new WorkflowRuntime();
_workflowRuntime.WorkflowCreated +=new EventHandler<WorkflowEventArgs>(_workflowRuntime_WorkflowCreated);
_workflowRuntime.WorkflowCompleted += new EventHandler <WorkflowCompletedEventArgs>(_workflowRuntime_WorkflowCompleted);
_workflowRuntime.ServicesExceptionNotHandled +=new EventHandler<ServicesExceptionNotHandledEventArgs>(_workflowRuntime_ServicesExceptionNotHandled);
_workflowRuntime.WorkflowAborted += new EventHandler<WorkflowEventArgs>(_workflowRuntime_WorkflowAborted);
SqlTrackingService ts = new SqlTrackingService(connectionString);//跟踪服务
_workflowRuntime.AddService(ts); SqlWorkflowPersistenceService ps = new SqlWorkflowPersistenceService(connectionString, true,
new TimeSpan(1, 0, 0), new TimeSpan(1, 0, 0)); //持久话服务
_workflowRuntime.AddService(ps); SharedConnectionWorkflowCommitWorkBatchService sc = new SharedConnectionWorkflowCommitWorkBatchService(connectionString);//事务服务
_workflowRuntime.AddService(sc);
_workflowRuntime.StartRuntime();
AutoResetEvent waitHandle = new AutoResetEvent(false);
WorkflowInstance instance = _workflowRuntime.CreateWorkflow(typeof(DefaultSQLServices.SimpleWorkflow));
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();
}
}
} static void _workflowRuntime_WorkflowAborted(object sender, WorkflowEventArgs e)
{
Console.WriteLine("Aborted!!!!");//这个提示信息输出了。
} static void _workflowRuntime_ServicesExceptionNotHandled(object sender, ServicesExceptionNotHandledEventArgs e)
{
Console.WriteLine("--------********" + e.Exception.Message);
} static void _workflowRuntime_WorkflowCreated(object sender, WorkflowEventArgs e)
{
Console.WriteLine("Created!!!!");
}
static void _workflowRuntime_WorkflowCompleted(object sender, WorkflowEventArgs e)
{
Console.WriteLine("_workflowRuntime_WorkflowCompleted Completed!!!!");
}
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");
} }
}
}
但是整个工作流执行完成后,系统自动删除 instancestate表的数据,所以无法查到数据。