views:

43

answers:

4

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 the 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...

+1  A: 

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

Kirk Woll
you mean calculate time between now and midnight lets say T... set the timer interval to T and within T have the desired code and after desired code T set up timer interval for 24 hours and launch time again...
Junaid Saeed
Yes, that's what I mean.
Kirk Woll
And if you think of it as a "refresh" timer, as opposed to a "date changed" timer, you could attach a number of events to it as required (including date changed).
Randolph Potter
A: 

You could add a timer control to the form and set the interval to 86400000 ms - calculating the initial value on first startup.

Doogie
A: 

Use a Timer to check for the current date every second. Every time it changes, you can create your new record in the database.

Timwi
having a timer checking everysecond isn't very different from a loop
Junaid Saeed
+1  A: 

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.

JustBoo
i like this as well... by the way i like much better than the timer.. but the thing is it has manually scheduled... it won't be a part of the a=solution
Junaid Saeed