.NET应用程序崩溃,对非托管资源的状态应用程序、状态、资源、NET

2023-09-07 08:45:15 作者:狂得像风

恰好像数据库连接,打开的文件,非托管资源是什么?当.NET应用程序(而不是Web应用程序)崩溃

what happens to the unmanaged resources like DB connections, open files,... when a .net application (not web app) crashes

推荐答案

这会发生同样的事情,当本机(C / C ++ /等)的应用程序崩溃。

The same thing that happens when a native (C/C++/etc) app crashes.

有关的大多数情况下,操作系统将立即清理。它会关闭文件句柄,互斥锁,网络连接和其他任何东西,操作系统负责。

For the most part, the Operating System will clean up immediately. It will close file handles, mutexes, network connections, and any other stuff that the OS was responsible for.

有关未提供的操作系统(例如到SQL服务器的连接)等资源,它是由两者的软件是负责该资源。由于雷克斯中号提到,SQL Server将坐在那里,直到连接超时,然后将其释放,但其他的第三方软件可以充当不同。

For other resources not provided by the OS (for example a connection to SQL server), it's up to whichever piece of software is responsible for that resource. As Rex M mentions, SQL server will sit there until the connection times out, and then it will release it, but other third party software may act differently.

这可能会导致问题,如果你得到一些非托管资源从一个蹩脚的一块第三方软件,因为它可能不是足够聪明,使用超时或类似的机制,和非托管资源可能只是从来没有得到释放。

This can cause problems if you're getting some unmanaged resource from a crappy piece of third party software, as it may not be smart enough to use timeouts or a similar mechanism, and the unmanaged resource might simply never ever get released.

这也可能导致问题,如果您的第三方软件有很长的超时。例如,如果SQL服务器连接超时时间为20分钟,而你在2分钟内死机20次,那么你已经有了20用完连接坐在那里,直到超时发生。您可以通过做这种事情自己跑出来的连接。

It can also cause problems if your third party software has long timeouts. For example, if the SQL server connection timeout is 20 minutes, and you crash 20 times in 2 minutes, then you've got 20 "used up" connections sitting there until the timeout happens. You can run yourself out of connections by doing this kind of thing.

 
精彩推荐
图片推荐