Click here to Skip to main content
       

C#

 
AnswerRe: C#,ASP.Net PinmvpAbhinav S1-Feb-13 8:16 
Questionhow to change the background color of a selected row in datagridview [modified] PinmemberNarVish31-Jan-13 21:37 
AnswerRe: how to change the background color of a selected row in datagridview PinmvpOriginalGriff31-Jan-13 22:21 
GeneralRe: how to change the background color of a selected row in datagridview PinmemberNarVish31-Jan-13 22:35 
GeneralRe: how to change the background color of a selected row in datagridview PinmvpOriginalGriff31-Jan-13 22:38 
GeneralRe: how to change the background color of a selected row in datagridview PinmvpRichard MacCutchan31-Jan-13 22:39 
GeneralRe: how to change the background color of a selected row in datagridview PinmvpOriginalGriff31-Jan-13 22:46 
AnswerRe: how to change the background color of a selected row in datagridview PinmvpRichard MacCutchan31-Jan-13 22:38 
GeneralRe: how to change the background color of a selected row in datagridview PinmemberNarVish31-Jan-13 22:45 
QuestionHow to write events in event log using Log4net Pinmembervenkatpappu31-Jan-13 21:28 
AnswerRe: How to write events in event log using Log4net PinmvpRichard MacCutchan31-Jan-13 22:11 
QuestionThread.Abort - using and lock statement Pinmemberdevvvy31-Jan-13 15:49 
AnswerRe: Thread.Abort - using and lock statement PinmvpDave Kreskowiak31-Jan-13 17:53 
GeneralRe: Thread.Abort - using and lock statement [modified] Pinmemberdevvvy31-Jan-13 17:59 
Dave Kreskowiak wrote:
The same as usually.

I don't like "Usually" ...
I read from somewhere that [^]lock(x) statement is syntactic sugar, that JIT compiler will autogenerate the following:

Monitor.Enter(o);
S0;
try {
S1;
} finally {
Monitor.Exit(o);
}

However, for some compiler architecture, your code will not cleanup properly if Thread.Abort called at point "S0" above before the generated try block, thus Monitor.Exit will not be exited.
But hold - I just found out the answer - I missed the update from the referenced post which says M$ corrected the problem:

Update 4/17/08: This was indeed fixed for the X64 JIT in Visual Studio 2008. Note that when compiling C# code targeting both X86 and X64, if you do not use the /o+ switch, this problem can still occur due to extra explicit NOPs inserted before the try.
 
The framework implements a method Monitor.ReliableEnter, by the way, that could be used to avoid orphaning locks in the face of thread aborts, but it's internal to mscorlib.dll. It sets an out parameter within a region of code that cannot be interrupted by a thread abort, which the caller can then check inside the finally block. The acquisition then gets moved inside so that, if the CALL is reached, the finally block is guaranteed to always run. You'd then write this instead:
 
bool taken;
try {
Monitor.ReliableEnter(o, out taken);
S1;
} finally {
if (taken)
Monitor.Exit(o);
}

 
Problem solved!
dev


modified 1-Feb-13 0:09am.

GeneralRe: Thread.Abort - using and lock statement PinmvpDave Kreskowiak31-Jan-13 19:05 
GeneralRe: Thread.Abort - using and lock statement Pinmemberdevvvy31-Jan-13 19:07 
GeneralRe: Thread.Abort - using and lock statement Pinmemberdevvvy6-Nov-13 17:13 
Questionbuild C# as windows app Pinmemberdcof31-Jan-13 12:12 
AnswerRe: build C# as windows app PinmemberMycroft Holmes31-Jan-13 13:51 
AnswerRe: build C# as windows app PinmvpDave Kreskowiak31-Jan-13 14:53 
AnswerRe: build C# as windows app PinmvpAbhinav S31-Jan-13 22:37 
AnswerRe: build C# as windows app PinprotectorPete O'Hanlon31-Jan-13 23:40 
QuestionC# and ADP (Automatic Data Processing) integration PinmemberDan_YYC31-Jan-13 5:18 
AnswerRe: C# and ADP (Automatic Data Processing) integration PinmemberDan_YYC4-Feb-13 3:56 
QuestionAuto relocate a label Pinmemberjustcop31-Jan-13 4:41 
AnswerRe: Auto relocate a label PinmvpAbhinav S31-Jan-13 6:13 
AnswerRe: Auto relocate a label PinmvpDave Kreskowiak31-Jan-13 7:02 
AnswerRe: Auto relocate a label PinmvpEddy Vluggen31-Jan-13 10:22 
QuestionUpload files over HTTPS PinmemberEdis Husic31-Jan-13 1:37 
QuestionADAM LDAP Authentification via user distinguishedName Pinmembermappy7501730-Jan-13 22:41 
QuestionSubreport Pinmembertheezin30-Jan-13 22:16 
AnswerRe: Subreport PinprotectorPete O'Hanlon30-Jan-13 22:22 
QuestionHow to write c# version of Delphi's Abort procedure PinmemberXiaoming Qian30-Jan-13 18:46 
AnswerRe: How to write c# version of Delphi's Abort procedure PinmvpRichard MacCutchan30-Jan-13 22:07 
AnswerRe: How to write c# version of Delphi's Abort procedure PinmemberShameel31-Jan-13 0:18 
AnswerRe: How to write c# version of Delphi's Abort procedure Pinmemberjschell31-Jan-13 8:21 
Question"new" to hide base class implementation - is it useless? [modified] Pinmemberdevvvy30-Jan-13 18:17 
AnswerRe: "new" to hide base class implementation - is it useless? PinmemberKeld Ølykke30-Jan-13 20:03 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy30-Jan-13 20:11 
GeneralRe: "new" to hide base class implementation - is it useless? PinmemberKeld Ølykke30-Jan-13 23:45 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy31-Jan-13 15:33 
GeneralRe: "new" to hide base class implementation - is it useless? PinmemberKeld Ølykke31-Jan-13 20:56 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy1-Feb-13 14:54 
AnswerRe: "new" to hide base class implementation - is it useless? [modified] Pinmembermarkovl30-Jan-13 21:20 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy31-Jan-13 15:30 
AnswerRe: "new" to hide base class implementation - is it useless? [modified] PinmemberShameel31-Jan-13 1:07 
AnswerRe: "new" to hide base class implementation - is it useless? PinmvpAbhinav S31-Jan-13 6:25 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy31-Jan-13 15:40 
GeneralRe: "new" to hide base class implementation - is it useless? PinmvpAbhinav S31-Jan-13 22:26 
GeneralRe: "new" to hide base class implementation - is it useless? Pinmemberdevvvy1-Feb-13 14:56 

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

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


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 31 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid