Day Change Update Problem
C# - Winforms - SQL Server
i am building an application which displays some data on the screen of the current day which it gets from the database... the application is like a desktop widget so the data is always visible on the desktop
the scheme i implemented is
when user commits some change to the data, after the update query i call the "update display" function... and the new data is retrieved...
by doing so i don't have too check constantly/periodically for changes in the database and data on the display is always current.. this sort of becomes PUSH technology
now it keeps track of the data in t开发者_运维问答he database for every day but only today's data is displayed... and when the program starts (manually\system start-up), it checks the date and
- if the record of the current day doesn't exist, it creates it and start display which can be later modified
- if the record exists then it just simply start display and there are interfaces available for modifying data
now the problem is
If the PC is running & Application is running at 12:00 pm and the date changes... There is no technique to check that :
- the day has changed and new record has to be created in database and the display needs to be refreshed
now i can continuously check via loop for the date change and solve my problem but i would love if there is a better option...
You could set a Timer upon program startup to notify you when midnight happens. i.e. If the program starts up at 8AM then set a timer to fire at midnight.
Link: http://msdn.microsoft.com/en-us/library/system.timers.timer(VS.71).aspx
You could add a timer control to the form and set the interval to 86400000 ms - calculating the initial value on first startup.
If you are on unix/linux you can run a cron job that kicks off an event. If you are on windows, set the task-scheduler to kick off an event.
And that event might be running a small app/script, stored procedure, etc., to do what you want.
Use a Timer to check for the current date every second. Every time it changes, you can create your new record in the database.
精彩评论