![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
scheduled events
hi all,
it is to my knowledge that the timer component or class is used like some kind of count down timer that triggers an event. Now how can i instead trigger an event(function) at a certain time or date. like calender event. on 22/12/2009 at 11:00 am. can this be done in an even triggered environment.. cause i can think of a very inefficient way of polling at every 5 minutes or so... but that is very wastefull! |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
Re: scheduled events
just retrive the system clock time and the check to see if it equal to the time you are after... surely that would work no.
Somehting like this C# Syntax (Toggle Plain Text)
Last edited by Freaky Chris; Mar 26th, 2008 at 7:29 PM. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
Re: scheduled events
yes that would definitely work. but you would have to poll that if statement on every second. isnt that kind of unpractical? isnt there some kind of event based approach?
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Re: scheduled events
if you were to use a timer you could acheive this perhaps,
so if you were to start a timer when the app loads, it checks the date that it should preform some function at. Compares it to the current date to check to see if it should run the function. if not it callsback to itself and check again etc. C# isn't really the area i code in so supply sample code is an issue but something like that should work...if not i'll re-think again
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#5 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: scheduled events
In VB, and C# I'm sure, you can adjust the DateTime to just show the date and evaluate the date. So you don't have to poll every second, you could poll twice a day, and if it finds the date it's looking for, BOOM goes the dynamite.
|
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: scheduled events
Create a timer in your class:
c# Syntax (Toggle Plain Text)
c# Syntax (Toggle Plain Text)
create the function to be called every tick and put Chris's code in it: c# Syntax (Toggle Plain Text)
|
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: scheduled events
There isn't a way to have a function called at a specific time - the only way to do it is to poll the clock. Of course, if you were to poll it once every minute or less, the processor time dedicated to your task would be so negligible that no one would care.
|
|
|
|
|
|
#8 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3
![]() |
Re: scheduled events
If you know the time you want it to fire at, you can sleep the thread for how long it takes to reach that time. Something along the lines of this pseudo-code:
DateTime target = "sometime"; Thread.Sleep(target - DateTime.Now); // do your task At work, we have a tool which basically runs on a timer every 15 seconds, checks an XML file to see if any of the tasks listed are due to run, and checks if any tasks have been added, then sleeps again. So, the polling is also a feasible design, give or take a few seconds.
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: scheduled events
And if the clock's wrong and the user changes it while you're sleeping?
|
|
|
|
|
|
#10 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3
![]() |
Re: scheduled events
Quote:
![]()
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Priority Queues Events | kruptof | C# | 12 | Sep 6th, 2007 5:56 PM |
| Implementation of Mouse Events. | smita | Existing Project Development | 3 | Mar 15th, 2007 3:11 PM |
| propagating mousemove events | Jimbo | JavaScript and Client-Side Browser Scripting | 4 | Sep 15th, 2006 1:20 PM |
| Clone Node Events | Eryk | JavaScript and Client-Side Browser Scripting | 2 | Feb 24th, 2006 2:15 PM |
| question: usage of delagates and custom events | melbolt | C# | 1 | Oct 3rd, 2005 7:17 PM |