数据库准备:

1. 创建database(这里我们用的是MSSQL。Workflow支持其它数据库,但是MSSQL是配置最方便,不要问我为什么!)。

2. 运行位于[%WINDIR%\Microsoft.NET\Framework\v4.xxx\SQL\EN]的的脚本文件SqlWorkflowInstanceStoreSchema.sql和SqlWorkflowInstanceStoreLogic.sql。这时数据库中表应该类似于下图:

开工:

1. 在上一个项目的基础上,引入System.Activites.DurableInstancing和System.Runtime.DurableInstancing。如下图所示:

2. 修改Console Project的program.cs如下:

         static void Main(string[] args)
{
// Workflow Store of SQL Server
SqlWorkflowInstanceStore store =
new SqlWorkflowInstanceStore("Data Source=192.168.3.26;Initial Catalog=workflow_hour3;Persist Security Info=True;User ID=sa;Password=M@nager"); AutoResetEvent syncEvent = new AutoResetEvent(false); Activity wf = new WorkflowsProject.Activity1(); // Create the WorkflowApplication using the desired
// workflow definition.
WorkflowApplication wfApp = new WorkflowApplication(wf); // Assign workflow store to the current workflow
wfApp.InstanceStore = store; wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
Console.WriteLine("Workflow {0} persisted at {1}",
e.InstanceId, System.DateTime.Now.ToLongTimeString());
return PersistableIdleAction.Persist;
}; wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
Console.WriteLine("Workflow {0} idled at {1}",
e.InstanceId, System.DateTime.Now.ToLongTimeString());
syncEvent.Set();
}; // Handle the desired lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
Console.WriteLine("Workflow {0} completed.", e.InstanceId.ToString());
syncEvent.Set();
}; wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
Console.WriteLine("Workflow {0} terminated because {1}", e.InstanceId, e.Reason.Message);
syncEvent.Set();
}; // Start the workflow.
wfApp.Run(); // Wait for Completed to arrive and signal that
// the workflow is complete.
syncEvent.WaitOne(); // Keep the console screen alive when workflow comnpletes
Console.WriteLine("Press enter to continue");
Console.Read();
}

3. 修改Delay的Duration为30秒,方便我们观察数据库的数据变化:

4. 运行。结果如下:

5. 在workflow persisted阶段,还没有到completed的时候,如果查看数据库中的[System.Activities.DurableInstancing].[InstancesTable]表,我们就会发现诸如如下的记录:

而当workflow运行到completed的时候,在查询这张表,就会发现这条记录已经不存在了。说明工作流的数据存储运行正确。

最新文章

  1. webstorm license key
  2. HTTP协议详解(转)
  3. .NET编译项目时出现《此实现不是 Windows 平台 FIPS 验证的加密算法的一部分》处理方法
  4. 浅谈JS中的继承
  5. 【Filter 页面重定向循环】写一个过滤器造成的页面重定向循环的问题
  6. POJ 1990 MooFest(树状数组)
  7. fastDFS 一二事 - 简易服务器搭建(单linux)
  8. C#中的volatile用法
  9. c/c++笔记
  10. linux 学习笔记 Linux内核的四大功能简介
  11. html 商品展示框
  12. ASP.NET实现图片防盗链(转)
  13. 转换汉字为字符原始码 如:汉字 -> 汉
  14. Little Puzzlers–List All Anagrams in a Word
  15. Leetcode 39 40 216 Combination Sum I II III
  16. centos7如何关闭防火墙
  17. 【Python】 压缩文件处理 zipfile & tarfile
  18. python学习之-用scrapy框架来创建爬虫(spider)
  19. IPv6应用普及,任重而道远
  20. 第一个Struts2实例之hello world!

热门文章

  1. 238 Product of Array Except Self 除自身以外数组的乘积
  2. Android Error:Failed to resolve: com.afollestad:material-dialogs:
  3. python模块中的__all__属性
  4. Pro ASP.NET Core MVC 第6版 第二章(后半章)
  5. 【PostgreSQL-9.6.3】使用pg_settings表查看参数的生效条件
  6. POJ_2239_Selecting Courses
  7. [JSOI2012]玄武密码 题解(AC自动机)
  8. Could not resolve type alias 'map '. Cause: java.lang.ClassNotFoundException: Cannot find class: map
  9. 安装svn
  10. java string与byte互转