This question relates to a comment in another posting here: Cancelling an Entity Framework Query
I will reproduce the code example from there for clarity:
Depending on whether you use using
or explicitly try/finally
you can have slightly different code using the sample code you will have
AdventureWorks2008R2Entities entities = null;
try // Don't use using because it can cause race condition
{
entities = new AdventureWorks2008R2Entities();
...
} finally {
}
substituting that with a using statement it could look like
using(var entities = new AdventureWorks2008R2Entities()){
...
}
which accordig do §8.13 of the specification will be expanded to
AdventureWorks2008R2Entities entities = new AdventureWorks2008R2Entities();
try
{
...
} finally {
}
Therefor the only real difference is that the assignment is not within the try/finally block but that has no consequence on which race conditions could occur (aside from thread abort inbetween the assignement and the try block as Hans also notes)