开发者

Failing fast in a winforms app

开发者 https://www.devze.com 2023-02-24 04:07 出处:网络
In a .NET application, if I get a fatal exception (e.g. OOM), I failfast. I do this by calling Environment.Exit() which calls finally blocks (it may be Environment.Failfast() which calls finally block

In a .NET application, if I get a fatal exception (e.g. OOM), I failfast. I do this by calling Environment.Exit() which calls finally blocks (it may be Environment.Failfast() which calls finally blocks, I use whichever one does), in my applicationthreadexception event handler.

Is this the correct way of faili开发者_Python百科ng fast?

Thanks


Environment.Failfast() does not run the finalizers, it puts an event in the Windows log and generates a minidump. You don't want to fill the client's machine with minidumps, they are not small files. And nobody is going to look at them.

Preventing finalizers on an OOM condition isn't very useful, finalizers are not going to allocate more memory. Use Environment.Exit(). Or just don't catch anything, OOM is very hard to catch anyway since it can be thrown anywhere. If you want to put effort into it then fix your code so it doesn't gobble so much memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消