We have a application written in C#, using WPF. It has a timer based activation event which leads to some drawing in a DirectX context.
All seems well, until we open child window, and move it around the screen. The timing seems to coincide with the timer getting fired, but at that moment, the entire screen (even other applications) seem to freeze, and the user is unable to click anywhere.
The normal operation resumes from the exact same point where it froze if one presses ALT+TAB key combination. During the frozen state, there is no rise in CPU/memory utilization which leads me to suspect some kind of blocking on the main thread.
Normally, if my application hangs in the middle of some operation, I'd go, press pause from Visual Studio, and see the thread view in the debugger. This gives me sufficient idea on which call is the culprit.
But in this case, if I press ALT+TAB to switch to IDE, my application resumes it's normal execution. If I place my IDE on secondary screen and try to click (without the need to press ALT+TAB), it appears to be frozen as well (As I previously mentioned, entire desktop seems to be frozen to mouse clicks. Mouse movement however is normal)
Any one faced/aware of a similar problem, and on how can I go on debugging it ?
Try using a BackgroundWorker process to run your timer in the background. I was having the exact same issue, and I used the BackgroundWorker and it fixed my issue. Here is some sample code to get you started:
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.RunWorkerAsync();
bw.Dispose();
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
//Do Stuff Here
return;
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//Do an action when complete
}
Just wrap that in your timers tick event and everything should function as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With