Tuesday, December 1, 2009

Form crashes when moving

0 Conmment
I ran into this problem a long time ago, when I did my original servo controller ( http://www.freescale.com/files/32bit/doc/app_note/AN3523.pdf?fsrch=1 ).

The problem occurs with both .NET and MFC forms. And the result of the problem is the application crashing when the window is moved.

I found the problem to be a timer that I had updating textboxes in my window. the problem went away if I disabled the timer.

I made many attempts at a solution, until I found one that worked the best. I simply disable, then re-enable the timer in the forms Move event. Now the Move event occurs continuously while you are moving, so the timer is being continuously disabled and enabled, which resets it. this keeps the timer from triggering while the window is being moved.

My timer was triggering every 100ms to update the form with data from the HID interface. So I still had a race condition that would cause occasional crashes. I fixed this by increasing the timer period to 1000ms when the window is being moved ( in the Move event ). Then in the timer trigger event, I reset the timer period to 100ms. So the result is that after the form is moved, the data does not update for a whole second after the form stops moving, but this perfectly acceptable, and everything goes back to normal 1 second after the move, and the window does not crash anymore.

Hope this helps somebody.

Comments

0 comments to "Form crashes when moving"

Post a Comment

Advertisement

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com