错误处理模式,使用WF多线程的应用程序? [英] Error handling patterns for multithreaded apps using WF?

查看:87
本文介绍了错误处理模式,使用WF多线程的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了很长的,详细的问题,而只是取消它,取而代之的是更简单的问题,我没有找到答案在这里。

I was writing up a long, detailed question, but just scrapped it in favor of a simpler question that I didn't find an answer to here.

简要程序描述:

我有一个WPF应用程序,会生成多个线程,每个线程执行自己的WF。什么是一些以处理线程和WF,将允许从GUI端用户交互错误的最好方法是什么?我肯定打算处理的线程任何低级别的例外,因为我不希望线程退出。

I have a WPF app that spawns several threads, and each thread executes its own WF. What are some of the best ways to handle errors in the threads and WF that will allow user interaction from the GUI side? I definitely plan to handle any low level exceptions in the thread, because I don't want the thread to exit.

问题总结:

  1. 你如何WF,并启动它的线程之间实现通信?有WorkflowTerminated,但我不希望工作流退出 - 我需要解决的问题,并让它继续。我认为唯一的选择是使用FaultHandler,但不知道是否有另一种方式来做到这一点,而无需使用活动块。我希望有一个框架在那里,我只是还没有找到。

  1. How have you implemented communication between WF and the thread that starts it? There is WorkflowTerminated, but I don't want the workflow to exit -- I need to fix the problem and let it continue. I assume the only option is using a FaultHandler, but was wondering if there's another way to do it without using an activity block. I am hoping there's a framework out there that I just haven't found yet.

需要从WF的错误被逮住的线程,则需要在GUI中显示错误。然后,用户将用于恢复一个合乎逻辑的选择,则这应被送回的​​线程,然后到WF。再次,是有什么存在在那里,我应该看看?

The error from WF needs to get caught by the thread, which then needs to display the error in the GUI. The user will then make a logical choice for recovery, which should then be sent back to the thread, and then to WF. Again, is there something existing out there that I should take a look at?

即使流行语/是完成我所描述将是非常有益的,我可以做跑腿他们每个人的研究关键字。但是,任何额外的观点永远是受欢迎的。 :)

Even buzzwords / keywords that accomplish what I am describing would be really helpful, and I can do the legwork on researching each of them. However, any additional insight is always welcome. :)

推荐答案

以下是我最终解决这个问题。但首先一点背景资料:

Here's how I ended up solving this problem. But first a little background info:

用户点击,导致糖果包装机开始运行GUI的按钮。这是通过一个命令,在视图模型,然后调用模型中的低级别的功能结合完成的。模型中的功能启动一个线程并执行一个状态机。

User clicks a button in the GUI that causes the candy packager to start running. This is done via a command binding in the ViewModel, which then calls a low-level function in the Model. The function in the model launches a thread and executes a state machine.

在某些时候,该机器将失败。如果是这样,我编译有关错误和可能的(已知)的恢复方法的信息。我把这个变成一个对象,然后它通过一个回调接口传递到GUI。在此期间,工作线程被阻塞等待一个事件才能完成设置。

At some point, the machine will fail. When it does, I compile information about the error and possible (known) recovery methods. I put this into an object and then pass it to the GUI via a callback interface. In the meantime, the worker thread is stuck waiting for an Event to get set.

最后,糖果工人会发现错误,并会点击一个按钮,告诉系统做什么。这导致了两件事:1)它的标志的回收方法为$ P $之一pferred之一,和2)设置该事件。现在的工作线程继续上,为preferred错误恢复方法检查,并过渡到状态机的相应状态。

Eventually, the candy worker will notice the error and will click a button telling the system what to do. This results in two things: 1) it flags one of the recovery methods as the preferred one, and 2) sets the event. Now the worker thread continues on, checks for the preferred error recovery method and transitions into the respective state in the state machine.

这工作得很好(到目前为止)。我知道的部分完全是跛脚的,在此检查为preferred错误恢复方法的方式。我本质上设置一个字符串变量,然后比较这串已知字符串列表。超扯,但我不知道一个更好的办法来做到这一点,除了使用枚举。有没有人有建议给我?

This works very well (so far). The part I know is totally lame is the manner in which it checks for the preferred error recovery method. I am essentially setting a string variable, and then comparing this string to a list of known strings. Ultra lame, but I'm not sure of a better way to do this, other than using an enum. Does anyone have recommendations for me?

这篇关于错误处理模式,使用WF多线程的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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