管理无&QUOT工作流程的生命周期,持久性服务" [英] Managing workflow lifecycle without a "persistence service"

查看:196
本文介绍了管理无&QUOT工作流程的生命周期,持久性服务"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows WF现在一个简单的方法,以状态机。事实上,我还没有使用状态机,我使用的是顺序工作流。最后,我会沟WF赞成别的东西,但因为我已经有code工作,我需要得到中止,暂停和恢复工作方法。

I'm using Windows WF right now for a simple way to state machines. In fact, I'm not even using a state machine, I'm using a sequential workflow. Eventually, I will ditch WF in favor of something else, but since I already have the code working, I need to get the Abort, Suspend, and Resume methods working.

我的应用程序产生一个线程,然后产生另一个线程拥有该WorkflowInstance。我的GUI有中止,暂停和恢复按钮在里面,而这些最终调用WorkflowInstance的中止,暂停和恢复分别方法。

My application spawns a thread, which then spawns another thread that owns the WorkflowInstance. My GUI has Abort, Pause, and Resume buttons in it, and these eventually call the WorkflowInstance's Abort, Suspend, and Resume methods, respectively.

现在的问题是,当我这样做,我得到一个非常大的和可怕的消息框,上面写着:

The problem is that when I do this, I get a very large and scary MessageBox that says:

工作流的托管环境没有所要求的操作上的工作流实例具有持久性服务

随着一个漂亮的堆栈跟踪和所有。现在,我抬起头来临WF这些方法由Bruce Bukovics 一他的实例调用这些方法,并没有提到一个持久化服务是任何地方。然而,他的榜样电话都是在WorkflowRuntime的范围之内,即他称之为是这样的:

along with a nice stack trace and all. Now, I looked up these methods in Pro WF by Bruce Bukovics and one of his examples calls these methods, and no mention of a "persistence service" was anywhere. However, his example calls were within the scope of the WorkflowRuntime, i.e he calls them like this:

using(WorkflowRuntimeManager manager = new WorkflowRuntimeManager(new WorkflowRuntime("WorkflowRuntime")))
{
  manager.WorkflowRuntime.StartRuntime();
  WorkflowInstanceWrapper instance = manager.StartWorkflow(typeof(SharedWorkflows.Workflow1), null);
  instance.Suspend("Manually suspended");
  instance.Resume();
  waitHandle.WaitOne();
}

在我的应用程序,我实现了WorkflowRuntime的作为一个单身,因为我发现,有一个巨大的内存泄漏,当我创建像这样的WorkflowRuntime。所以,我的code是这样的:

In my app, I implemented the WorkflowRuntime as a singleton because I found that there was a huge memory leak when I created the WorkflowRuntime like this. So my code looks like this:

WorkflowInstance instance = WorkflowRuntimeSingleton.Instance.workflow_runtime.CreateWorkflow(typeof(SharedWorkflows.Workflow1), null);
instance.Start();
instance.Suspend("Manually suspended");
instance.Resume();
waitHandle.WaitOne();

现在,如果我叫暂停和恢复,如上图所示,它工作正常。但是,如果我发出通过我的GUI呼叫时,报告说的持久性服务。

Now, if I call Suspend and Resume as shown above, it works fine. But if I issue the call via my GUI, it complains about the persistence service.

鉴于此信息,而且我不希望建立一个数据库,只是为了让这三个功能,我想知道什么,我需要做的,使这项工作。在这一点上我最好的猜测是,WF不喜欢从一个单独的线程来控制。如果是这样的话,有什么好办法来进行调用看起来好像是从同一个线程发出?

Given this information, and that I do not want to set up a database just to get these three functions, I'd like to know what I need to do to make this work. My best guess at this point is that WF doesn't like being controlled from a separate thread. If that's the case, is there a good way to make the call seem as though it is issued from the same thread?

下面是我想出了一些可能的解决办法,但我敢肯定有人在这里有一个方法发烧友和优雅的方式来做到这一点。

Here are some possible solutions that I've come up with, but I'm sure someone here has a way fancier and elegant way to do it.

  1. 通过一个界面GUI WF轮询中止/暂停/恢复(看来真的跛脚)
  2. 替换WaitOne的()用了WaitAny(),并有图形用户界面调用到拥有该工作流设置的AutoResetEvent对象。了WaitAny()允许继续执行,然后我的code可以检查哪个按钮,用户pressed。这将需要被包装在一个循环,这样,直到用户点击中止,或者我们可以再次等到WF完成。
  3. 使用布尔标志,基本上做什么,#2在做什么。
  4. 看看有没有人在SO知道如何拨打电话奇迹般地走在了正确的线程:)

任何见解或意见将是非常美联社preciated!

Any insight or opinions would be really appreciated!

推荐答案

它不是什么大不了的事,以创建持久性数据库。事实上,它会帮助你的内存问题,因为它仍然存在被暂停超过给定的时间周期较长的工作流程(取出来的内存)。这里是一个链接,以帮助您创建数据库,并使用它在您的工作流程:的 http://msdn.microsoft.com/en-us/library/ms735722(VS.85)的.aspx

Its not that big of a deal to create the persistence database. In fact, it will help your memory problems, because it persists the workflows that are suspended for longer than a given period of time (taking them out of memory). Here is a link to help you create the database and use it in your workflow: http://msdn.microsoft.com/en-us/library/ms735722(VS.85).aspx

在连结,它提到改变你的app.config。我没有做到这一点。相反,我添加了code的服务。像这样的:

In the link, it mentions changing your app.config. I didn't do this. Instead, I added the service in code. Like this:

//Add the persistence service
WorkflowPersistenceService persistenceService = new SqlWorkflowPersistenceService(
    DBConnections.PersistenceService,
    true,
    TimeSpan.MaxValue,
    new TimeSpan(0, 0, 15));
m_WorkflowRuntime.AddService(persistenceService);

编辑:另一个有用的链接

这篇关于管理无&QUOT工作流程的生命周期,持久性服务"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆