Do IDisposable objects get disposed of if the program is shut down unexpectedly?

前端 未结 6 1732
借酒劲吻你
借酒劲吻你 2021-01-17 07:31

What happens if the program exits unexpectedly (either by exception or the process is terminated)? Are there any situations like this (or otherwise) where the program will t

6条回答
  •  长发绾君心
    2021-01-17 08:12

    If the program quits unexpectedly (for example you kill the process) there are absolutely no guarantees that the IDisposable.Dispose method will be called. You'd better not rely on it for such events. The Dispose method must be called manually by your code, it's not something that the CLR will call automatically for you.

提交回复
热议问题