Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
QuestionError in connection string Pin
Azza ALbelushi18-Feb-13 3:56
Azza ALbelushi18-Feb-13 3:56 
AnswerRe: Error in connection string Pin
Deflinek18-Feb-13 4:40
Deflinek18-Feb-13 4:40 
GeneralRe: Error in connection string Pin
Azza ALbelushi18-Feb-13 4:53
Azza ALbelushi18-Feb-13 4:53 
GeneralRe: Error in connection string Pin
Deflinek18-Feb-13 22:32
Deflinek18-Feb-13 22:32 
QuestionEvil Thread.Abort and using(TransactionScope) -- what will happen? Pin
devvvy18-Feb-13 2:41
devvvy18-Feb-13 2:41 
AnswerRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
BobJanova18-Feb-13 2:59
BobJanova18-Feb-13 2:59 
AnswerRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
Eddy Vluggen18-Feb-13 3:01
professionalEddy Vluggen18-Feb-13 3:01 
AnswerRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
Pete O'Hanlon18-Feb-13 4:51
mvePete O'Hanlon18-Feb-13 4:51 
No, you can't guarantee that the Dispose method will be reached with Thread.Abort - this applies to pretty much any disposable class wrapped with using, and is not specific to TransactionScope. To understand why this is the case, it's important to understand that Thread.Abort is triggered as an asynchronous exception (unlike most other exceptions which are synchronous). This means that there is no guarantee as to when the exception is raised.

As you've pointed out, the using pattern is effectively syntactic sugar for try/finally, and I'm a really big fan of it. Thread.Abort, however, tramples over this sandbox because of a nasty little timing issue. If your code is lucky enough to abort during the bit in the body of the using statement, then the finally part, and that's a fine thing. If, however, your code has just to say entered the finally portion and the abort exception is raised, the code will drop out of the finally block at the point that it encounters the exception - even if it hasn't called Dispose yet.

However, apart from forcing termination of the program, I have never seen a system that really needs a Thread.Abort as there are generally other, safer methods to cancel a thread. Use of Thread.Abort is generally recommended by people who aren't aware that there are issues with using it, as it is an easy method to implement.
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier


modified 18-Feb-13 12:24pm.

GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
devvvy18-Feb-13 5:23
devvvy18-Feb-13 5:23 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
Pete O'Hanlon18-Feb-13 5:25
mvePete O'Hanlon18-Feb-13 5:25 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
devvvy18-Feb-13 5:53
devvvy18-Feb-13 5:53 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
jschell18-Feb-13 9:01
jschell18-Feb-13 9:01 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
Pete O'Hanlon18-Feb-13 9:05
mvePete O'Hanlon18-Feb-13 9:05 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
jschell19-Feb-13 9:00
jschell19-Feb-13 9:00 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
Pete O'Hanlon19-Feb-13 9:22
mvePete O'Hanlon19-Feb-13 9:22 
GeneralRe: Evil Thread.Abort and using(TransactionScope) -- what will happen? Pin
jschell20-Feb-13 8:07
jschell20-Feb-13 8:07 
Questionmicrosoft SQL 2005 and dot NET Framework Pin
abbasnafiu18-Feb-13 1:28
professionalabbasnafiu18-Feb-13 1:28 
AnswerRe: microsoft SQL 2005 and dot NET Framework Pin
Keith Barrow18-Feb-13 1:59
professionalKeith Barrow18-Feb-13 1:59 
GeneralRe: microsoft SQL 2005 and dot NET Framework Pin
abbasnafiu18-Feb-13 9:26
professionalabbasnafiu18-Feb-13 9:26 
AnswerRe: microsoft SQL 2005 and dot NET Framework Pin
Azza ALbelushi18-Feb-13 4:00
Azza ALbelushi18-Feb-13 4:00 
GeneralRe: microsoft SQL 2005 and dot NET Framework Pin
Dave Kreskowiak18-Feb-13 4:55
mveDave Kreskowiak18-Feb-13 4:55 
Questionc# middleware for distributed system Pin
Dioblos17-Feb-13 23:31
Dioblos17-Feb-13 23:31 
AnswerRe: c# middleware for distributed system Pin
Garth J Lancaster17-Feb-13 23:47
professionalGarth J Lancaster17-Feb-13 23:47 
GeneralRe: c# middleware for distributed system Pin
Dioblos18-Feb-13 0:10
Dioblos18-Feb-13 0:10 
GeneralRe: c# middleware for distributed system Pin
Garth J Lancaster18-Feb-13 12:22
professionalGarth J Lancaster18-Feb-13 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.