I'm experiencing a strange "freezing" issue in a C# WinForms application I developed. Here are the symptoms:
The program will at seemingly random times freeze the GUI. This means that no UI element can be selected. The app's windows can't be moved or resized. It feels like there's an invisible modal dialog on top.
Here's what I have found out so far:
- Code calls to GUI elements will go through normally, but UI elements don't reflect the change at all.
- The windows task manager does NOT classify my app as "not responding". Everything is normal from that perspective, even CPU usage is just around 1-2%. So I'm not in an infinite loop.
- The problem can not be provoked by any specific action, or I haven't found the "rule" yet. I did notice that when I use screenshot tools (like "demo builder") the problem seems to appear sooner. But I have no idea if and why this could be connected to my problem.
- The problem is not caused by an active user interaction. It can occur at any time even when no user interaction is going on.
- Among other things I have a threaded timer that's run every 5 seconds, and my log tells me that the timer's elapsed-method is called normally even after the UI freezing has started. So it's not the entire application that's blocked, just the UI.
- When I attach the debugger and pause, nothing special can be observed. It'll break at Application.Run(). There are several threads but all of them are on "external code", so nothing I can really debug.
- My program never recovers from the frozen state by itself. It stays that way, except in one case:
- When I attach the debugger after the freeze, then hit "Pause" and leave the program in paused state for maybe 1-2 minutes and then continue execution, the UI freeze will miraculously go away! The program is then back to normal until the next freeze.
Here are a few special things I do in my app:
- I wait for TAPI calls in a background thread (AddTAPI.NET component) and react to incoming calls. But I synchronize every call to the GUI using Control.BeginInvoke
- I have a threaded timer running every 5 seconds in which I send a short message to a WCF service.. basically just saying "hi I'm still alive"
- I use WCF client-/server communication with a client callback interface. Some calls from server to client cause GUI updates, but again, I'm always using Control.BeginInvoke to synchronize. Apart from that, the problem occurs even when there's no special communication from server to client.
Any ideas where or how to look for the cause of this strange problem is greatly appreciated!