I have a difficult to diagnose issue with a .NET Forms application where the UI Blocks whilst running the debugger.
The block is random and whilst blocked, if I click the pause button within the debugger it doesn’t actually complete the pause until the block releases.
I have tried the program outside the debugger by just running it and it doesn’t block and runs fine.
I have tried to use a profiler (ants) to find the block but whilst in this state it doesn’t block either and the profiler report doesn’t show anything noteworthy.
The application has background threads running to handle Socket Connectivity timeouts (with Threading.Timer these do not communicate with the UI).
The network operations are using BeginXXX calls.
I’m stumped with trying to find this issue because it doesn’t occur for users, but makes it difficult trying to debug other aspects of the program whilst these blocks seem to take place.
The main focus of the UI is a user control displaying a grid of Machines with their connectivity state retrieved from a State object (POSTerminal) from the UI thread,
Is there anything I can look at to possibly find a connection between the Debugger/UI blocking?
I eventually tracked this down. What was happening is that multiple threads where raising events that were making their way back to the main form.
In the form it was checking for the
InvokeRequiredand thenBeginInvokethis event back onto the mainform thread. The problem was that there was a bug in the event raising that was raising thousands of events and each was being invoked which has a lock in the check on the form. Hence causing the program (and debugger) to freeze.I wouldn’t have expected the debugger to freeze, but it did until all the locks/invokes had been processed before the Pause/Stop in the debugger could be pressed.