|
-
March 31st, 2008, 07:22 PM
#1
Something about C# events that I don't understand.
Why does this occur?
I have a piece of code that looks like the the following:
Code:
void MyEvent()
{
if( m_bDoSomething )
{
DoSomething();
m_bDoSomething = false;
}
}
By default "m_bDoSomething" is set to true.
MyEvent() is a function that a C# delegate gets mapped to.
The bug is that "DoSomething" gets called twice in a row.
MyEvent() appears to be triggered twice in my application but as I step through the debugger it "appears" that this function is called from two separate threads.
For instance, I set break points at DoSomething() and m_bDoSomething.
Here is the sequence of break points that I see in the debugger.
1. DoSomething();
2. DoSomething();
3. m_bDoSomething = false;
4. m_bDoSomething = false;
You would think... no problem... just synchronize this function...
HOWEVER, the debugger reports only one thread throughout the sequence above and also in our log files when we report the thread ID along with a trace statement in MyEvent()
Can anybody shed light on what may be happening here?
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|