VS 2005 is a Windows application written in 2005. This app asks the question against the SQL database in the timer cycle every 2 minutes. If any data changes happen, the window will be refreshed with new data.
If the user leaves the window, the windows will be locked shortly afterwards. There is no point in keeping data inquiries in 2 minutes when the windows are locked; Therefore, I would like to stop the query if the lock is turned on so as to reduce network data traffic and save existing window resources such as memory and CPU.
I'm not sure what is the way to find out if existing windows are locked? Not sure if there is any Windows API for this purpose, if not, then the net class is available?
My project is in Net 2.0 and all users are in Windows XP.
You do not really want to ask if the window is locked , Instead of the one you want to ask is that your application visible - if your window is minimized or covered from another window, then it is okay?
The standard way to go about this timer and window through. Use timer to schedule 2 minutes in the future. When the timer fires, it can cancel your window.
When you invalidate the window, Windows will send the "Paint" message to the OnPaint
handler, you update the screen with your data. But here's the kicker: If your window is not visible, then the Windows will not not OnPaint
event (in which the screen is turned on)!
Now, your database query is probably too expensive to execute in OnPaint
event handlers, so you may have to make some difficulties in your timer handler. For example, You can query the database in the timer handler and then call Form.Invalidate ()
. This means that when you come back from locking the screen, then your data may be out of date so that you can see if the DateTime.Now
timer handler and onpint
If the handler and one, then schedule the second timer directly. Otherwise, schedule the timer to run again with your OnPaint
callback in two minutes.
I hope all this makes sense :)