Question as per title.
I have a piece of code that does this:
using (SqlConnection dbcon = new SqlConnection(connectionString))
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(statement, dbcon))
{
dat_set = new System.Data.DataSet();
dbcon.Open();
dataAdapter.Fill(dat_set, name);
}
when I force exit the program when the dataAdapter is still filling the data set, the program freeze and stop responding.
I know "using" block release the resource when they go out of scope, but in the case of force termination, does the resources get release gracefully?
If a process exits, all the native resources (network handles, file handles etc) are cleared up by the operating system. I wouldn't expect the using
statement to come into effect here - I suspect the OS will kill the threads too hard for it to get a chance to do the clean-up itself. That means you'll still end up with the clean-up being done... but any flushing you might expect to happen as part of a using
statement (e.g. in a file writing scenario) may not happen.
See more on this question at Stackoverflow