المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Evil Thread.Abort and using(TransactionScope) -- what will happen?



C# Programming
02-18-2013, 06:10 PM
hi,

I dig around (http://stackoverflow.com/questions/3923457/is-cs-using-statement-abort-safe)[^ (http://stackoverflow.com/questions/3923457/is-cs-using-statement-abort-safe)]understand that depending on compiler architecture using statement is actually a syntactic sugar ...

Translate FROM:

using (TransactionScope scope = new TransactionScope())
{
...
}


TO:

TransactionScope scope = new TransactionScope();
#PT1#
try {
...
#PT2#
scope.Complete();
#PT3#
} finally {
if (scope!= null)
((IDisposable)scope).Dispose();
}


Previously, as I read, depending on compiler architecture code may blow up at #PT1# and thus finally cleanup block would never execute. But again, I read further that Microsoft already fixed this problem.

What I want to ask is, is using(TransactionScope) now Thread.Abort safe? If code blows up at #PT2# and not #PT3#, would "scope.Dispose" rollback the transaction as well?

Thanks
dev