从第三方组件preventing异常崩溃的整个应用程序 [英] Preventing Exceptions from 3rd party component from crashing the entire application

查看:214
本文介绍了从第三方组件preventing异常崩溃的整个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写依赖于一些第三方的DLL多线程应用程序。我的问题是,当从第三方库使用对象,如果它抛出一个异常,同时运行,我无法抓住它,它冒泡并杀死整个应用程序。我有很多不同的线程分别使用自己的对象,从这个第三方库,我需要的是使用对象的副本,以便能够捕捉和处理异常的线程。

I am writing a multi-threaded application that relies on some third party DLLs. My problem is that when using an object from the third party library, if it raises an exception while running, I am unable to catch it and it bubbles up and kills the entire application. I have many different threads each using its own object from this third party library and I need the thread that was using that copy of the object to be able to catch and deal with the exception.

根据我读过,这似乎是最有可能的第三方库实际上是让自己的线程,并允许未捕获的异常。在.NET 2.0 +行为使这些异常杀死整个应用程序。我知道AppDomain.CurrentDomain.UnhandledException的,但是,这并不让你prevent应用程序关闭。

Based on what I've read, it seems like most likely the 3rd party library is actually making its own threads and allowing uncaught exceptions. The .NET 2.0+ behavior allows these exceptions to kill the entire application. I'm aware of AppDomain.CurrentDomain.UnhandledException, but that does not allow you to prevent application shutdown.

有关的参考,我写在.NET 4.0中一个控制台应用程序。没有人有任何解决方案/建议,以杀死我的应用程序停止这些例外?

For reference, I'm writing a console application in .NET 4.0. Does anyone have any solution/advice to stop these exceptions from killing my application?

推荐答案

你可能看一件事就是HandleProcessCorruptedStateExceptionsAttribute属性。

One thing you might look at is the HandleProcessCorruptedStateExceptionsAttribute attribute.

我不知道这是不是你的问题或没有,但我不得不最近使用该属性上被调用第三方COM对象功能的方法。此属性是新的.NET 4.0。我的基本理解是,4.0框架将在默认情况下不能上升扔在某些情况下个例外,在它认为第三方异常可能已经推出了一些instabilty。我认为这涉及到大部分情况下,第三方组件的非托管。我不知道,但它解决了我的问题。

I don't know if this is your problem or not, but I had to recently use this attribute on a method that was calling a function in a third party COM object. This attribute is new to .net 4.0. My basic understanding is that the 4.0 framework will by default not bubble up an exception thrown in certain situations where it feels the 3rd party exception may have introduced some instabilty. I think this pertains mostly to situations where the 3rd party component is unmanaged. I am not sure, but it resolved my issue.

的用法是这样的:

[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute()]
private void ThirdPartyCall()
{
    try
    {
            return Call3rdPartyFunction()
    }
    catch (Exception exInstantiate)
    {
        ...
    }
}

详细信息:<一href="http://msdn.microsoft.com/en-us/magazine/dd419661.aspx">http://msdn.microsoft.com/en-us/magazine/dd419661.aspx

这篇关于从第三方组件preventing异常崩溃的整个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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