Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I need to create a function where it executes something after a certain time of day. For example : execute some code after 5:30 PM. I've tried comparing two timespan values but it doesn't work. It executes the code even before the designated time. I'm using a timer. Any ideas?
Posted

You can have window service to start and process some specific task on specific time. Here is a good example.

http://www.c-sharpcorner.com/UploadFile/prvn_131971/BirthdayWishScheduler02022006012557AM/BirthdayWishScheduler.aspx[^]
 
Share this answer
 
Comments
nagendrathecoder 7-Jun-11 2:57am    
Sahi re Kiran. :)
Sergey Alexandrovich Kryukov 7-Jun-11 2:58am    
Right, my 5. However, there is much simpler way -- Scheduler Service.
Please see my solution.
--SA
In addition to the solution by Kiran:

There is a much simpler solution.

You can also use available Scheduler Service. To schedule a run of your code, use Windows command schtasks.exe or at.exe.
See:
http://en.wikipedia.org/wiki/At_(Windows)[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://msdn.microsoft.com/en-us/library/bb736357(v=vs.85).aspx[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^].

More on Task Scheduler:
http://msdn.microsoft.com/en-us/library/aa383614(v=VS.85).aspx[^],
http://msdn.microsoft.com/en-us/library/aa383608(v=VS.85).aspx[^].

—SA
 
Share this answer
 
Comments
thatraja 7-Jun-11 3:41am    
Good bunch, bookmarked.
Sergey Alexandrovich Kryukov 7-Jun-11 16:22pm    
Thank you, Raja.
--SA
Kim Togo 7-Jun-11 3:50am    
My 5. Scheduler Service is an overlooked feature.
Sergey Alexandrovich Kryukov 7-Jun-11 16:25pm    
Thank you Kim.
It is overlooked. I used to use it when I used public transportation for commute: you miss the evening train at work, wait for next one for two hours. Now I noticed I fail to remember things like birthdays and even forget to pay some bills in time. Scheduler Service will alert me perfectly as it did for my train. :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900