Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET/C# debugging: How to debug a classical heisenbug?
    text
    copied!<p>Recently, I've run into a classical <a href="http://en.wikipedia.org/wiki/Unusual%20software%20bug#Heisenbug" rel="nofollow">Heisenbug</a>. Here's the situation:</p> <ul> <li>I have a tree list, the master view, in one panel, and a detail view in another panel to the right, that displays information about the currently selected tree node. (Very similar to Windows Explorer.)</li> <li>When I add a new node to tree (think of right-clicking a folder in Windows Explorer and saying "New -> Folder"), the newly created node gets selected.</li> <li>And here's the bug: The detail view on the right should get updated to show the new node. However, it doesn't. I have to switch to another tree node once, before I can see information about the new node in the detail view.</li> </ul> <p>The bug is easily reproducible and happens in both "Release" and "Debug" build configurations. But: As soon as I set a breakpoint in the event handler (for the "Add new node" menu entry) and enable it, everything works fine =>Heisenbug! I don't have to do any real debugging. Clicking "continue" after the breakpoint gets hit is enough.</p> <p>For better understanding, I've made <a href="http://www.youtube.com/watch?v=DCwT81D8moo" rel="nofollow">a video</a> that should illustrate what's going on.</p> <p>Everything I could think of to get rid of the issue was putting the thread (the application is single-threaded) to sleep for a few seconds, but that doesn't work.</p> <p>I'd greatly appreciate any suggestions on what I could try to determine the cause of the issue. Or maybe someone has a guess about the cause?</p> <p>I'm targeting the 3.5 framework and using x86 as solution platform. The tree list control is from <a href="http://devexpress.com/" rel="nofollow">DevExpress'</a> WinForms controls; Visual Studio version is 2010.</p> <p>Thanks</p> <hr> <p>Update 3: <strong>Issue solved</strong>. The problem was that the call to the detail view's Focus() method didn't trigger the GotFocus event, which is crucial for updating the detail view. (I don't know why, probably it already had the focus.) However, the method did not fail, it simply did nothing.</p> <p>Now I just focus another control before focussing the detail view and that's it. The reason why everything worked fine during debugging was that switching from Visual Studio back to my application correctly set the focus on the detail view.</p> <p>A major obstacle in hunting down this issue was that setting a breakpoint in the GotFocus event handler is useless: anytime you try to switch back from Visual Studio to the app, the GotFocus event gets re-triggered, and you're stuck in an endless loop. Comments on how that could be worked around are welcome.</p> <p>Anyway, my specific problem is solved.</p> <p>Thank you very much to everybody who answered or commented. It helped me a lot.</p> <hr> <p>Update 2: In my code, I select the newly created node in the tree. This triggers a FocusedNodeChangedEvent. In the corresponding event handler, I update the detail view and call its Focus() method.</p> <p>It seems as if that fails when there's no breakpoint set. I think what triggers the correct update during debugging is that the detail view automatically gets the focus.</p> <hr> <h2>Window messages</h2> <p>Update 1: Here are the window messages that Eddy's answer provided. (Long list of messages deleted)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload