Click here to Skip to main content
12,066,952 members (59,394 online)
   

C#

 
GeneralRe: how to change the background color of a selected row in datagridview Pin
OriginalGriff31-Jan-13 23:46
mvpOriginalGriff31-Jan-13 23:46 
AnswerRe: how to change the background color of a selected row in datagridview Pin
Richard MacCutchan31-Jan-13 23:38
mvpRichard MacCutchan31-Jan-13 23:38 
GeneralRe: how to change the background color of a selected row in datagridview Pin
NarVish31-Jan-13 23:45
memberNarVish31-Jan-13 23:45 
QuestionHow to write events in event log using Log4net Pin
venkatpappu31-Jan-13 22:28
membervenkatpappu31-Jan-13 22:28 
AnswerRe: How to write events in event log using Log4net Pin
Richard MacCutchan31-Jan-13 23:11
mvpRichard MacCutchan31-Jan-13 23:11 
QuestionThread.Abort - using and lock statement Pin
devvvy31-Jan-13 16:49
memberdevvvy31-Jan-13 16:49 
AnswerRe: Thread.Abort - using and lock statement Pin
Dave Kreskowiak31-Jan-13 18:53
mvpDave Kreskowiak31-Jan-13 18:53 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy31-Jan-13 18:59
memberdevvvy31-Jan-13 18: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 Pin
Dave Kreskowiak31-Jan-13 20:05
mvpDave Kreskowiak31-Jan-13 20:05 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy31-Jan-13 20:07
memberdevvvy31-Jan-13 20:07 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy6-Nov-13 18:13
memberdevvvy6-Nov-13 18:13 
Questionbuild C# as windows app Pin
dcof31-Jan-13 13:12
memberdcof31-Jan-13 13:12 
AnswerRe: build C# as windows app Pin
Mycroft Holmes31-Jan-13 14:51
memberMycroft Holmes31-Jan-13 14:51 
AnswerRe: build C# as windows app Pin
Dave Kreskowiak31-Jan-13 15:53
mvpDave Kreskowiak31-Jan-13 15:53 
AnswerRe: build C# as windows app Pin
Abhinav S31-Jan-13 23:37
mvpAbhinav S31-Jan-13 23:37 
AnswerRe: build C# as windows app Pin
Pete O'Hanlon1-Feb-13 0:40
protectorPete O'Hanlon1-Feb-13 0:40 
QuestionC# and ADP (Automatic Data Processing) integration Pin
Dan_YYC31-Jan-13 6:18
memberDan_YYC31-Jan-13 6:18 
AnswerRe: C# and ADP (Automatic Data Processing) integration Pin
Dan_YYC4-Feb-13 4:56
memberDan_YYC4-Feb-13 4:56 
QuestionAuto relocate a label Pin
justcop31-Jan-13 5:41
memberjustcop31-Jan-13 5:41 
AnswerRe: Auto relocate a label Pin
Abhinav S31-Jan-13 7:13
mvpAbhinav S31-Jan-13 7:13 
AnswerRe: Auto relocate a label Pin
Dave Kreskowiak31-Jan-13 8:02
mvpDave Kreskowiak31-Jan-13 8:02 
AnswerRe: Auto relocate a label Pin
Eddy Vluggen31-Jan-13 11:22
mvpEddy Vluggen31-Jan-13 11:22 
QuestionUpload files over HTTPS Pin
Edis Husic31-Jan-13 2:37
memberEdis Husic31-Jan-13 2:37 
QuestionADAM LDAP Authentification via user distinguishedName Pin
mappy7501730-Jan-13 23:41
membermappy7501730-Jan-13 23:41 
QuestionSubreport Pin
theezin30-Jan-13 23:16
membertheezin30-Jan-13 23:16 

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.


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 8 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid