Prism:异常处理?

发布于 2024-08-22 17:27:37 字数 347 浏览 1 评论 0原文

我在我正在编写的 Prism 应用程序中的复合事件处理程序中得到了奇怪的结果。我创建了事件处理程序并放入异常语句以验证是否正在调用该处理程序:

public void OnDateSelected(DateTime selectedDate)
{
    // Temporary code
    throw new ApplicationException("Not implemented yet.");
}

我运行应用程序并引发事件。事件处理程序被调用,但异常不会停止执行。它被写入输出窗口,应用程序退出处理程序,但执行继续。看不到任何地方的 try-catch 块,那么为什么异常没有中断执行呢?谢谢。

I'm getting an odd result in a Composite Event handler in a Prism app I am writing. I created the event handler and put in an exception statement to verify that the handler is being called:

public void OnDateSelected(DateTime selectedDate)
{
    // Temporary code
    throw new ApplicationException("Not implemented yet.");
}

I run the app and raise the event. The event handler is called, but the exception does not stop execution. It is written to the output window, and the app exits the handler, but execution continues. There isn't a try-catch block anywhere in sight, so why isn't the exception interrupting execution? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-08-29 17:27:37

我们在这里找到了问题所在。我们正在使用 v2.2 的 prism 库。在BackgroundEventSubscription 类中,当发布事件时,将创建并调用后台工作者。 RunWorkerCompleted 委托永远不会被处理,因此永远不会在任何地方拾取异常。棱镜库也没有为最终用户提供在此版本中应用自己的委托的简单方法。解决方案是编译您自己的一组库并使用线程池(这就是我们所做的)或覆盖您自己的 CompositePresentationEvent 类的 Subscribe 并使用您自己的事件订阅类来执行您需要的操作。

prism v4 库已经解决了这个问题,因为它使用线程池,因此任何未处理的异常都会冒泡到域未处理的异常处理程序(如果您指定了一个)。

谢谢。

We figured out the problem here. We are using v2.2 of the prism libraries. In the BackgroundEventSubscription class, when the event is being published, a background worker is created and invoked. The RunWorkerCompleted delegate is never handled so the exceptions are never picked up anywhere. The prism library also does not give the end user a simple way to apply their own delegate in this version. The solution is to either compile your own set of libraries and use the threadpool (this is what we did) or override Subscribe of your own CompositePresentationEvent class and use your own event subscription class that does what you need.

The prism v4 libraries have addressed this issue as it is using the thread pool so any unhandled exceptions will bubble up to the domain unhandled exception handler (if you specified one).

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文