I open a database connection in a try block. If I step into the try block, and then stop debugging, would the finally block be executed? In other words, does the connection remain open?
If by "stop debugging" you mean stopping the application of course not (for example stopping the current debug session pressing the stop button inside Visual Studio). This is the typical case for a console application launched by pressing F5 button.
If by "stopping" you mean "detaching" from currently running application launched outside VS (for example the one you attached with Ctrl+Alt+P), the program will run to it's end and will do everything is programmed for. It's also true for any web application which is running inside IIS (but not the IIS express).
No, if you terminate the app from your debugger, the finally block is not executed. The entire process is killed. Indeed, this may lead to undisposed references. (If you just detach, it keeps running)
The connection will not remain open though. The server will disconnect sooner or later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With