Do IDisposable objects get disposed of if the program is shut down unexpectedly?
问题 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 terminate, but IDisposable objects won't be properly disposed of? The reason I'm asking is because I'm writing code that will communicate with a peripheral, and I want to make sure there's no chance it will be left in a bad state. 回答1: If the cause is an exception and thrown from within a using block or a try catch finally