Click here to Skip to main content
15,884,603 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
How can one execute a method at a specific time where that time is stored in a variable. The variable gets the time from a database so the user can specify that time in the database. If it is compared to the windows time the program automatically should execute said method.
Is it possible to have this method execute even if the program is not running. I mean something like an out of process service or a windows service.

[edit]Spurious bold and code block removed - OriginalGriff[/edit]

Hello everyone!
Thanks for all your answers. Let's keep it simple: I have a method I want the user to be able to execute at a time this user specified. This time should be stored in a database and the program automatically retrieves that time and it compares to the windows time the method should be run automatically once every day at that time. I don't know how to do this while the program is running and I was just wondering if this operation is possible while the program is not running, but it's more important to me to make this work while the program I intent to write is running.

Thanks again!
Posted
Updated 29-Apr-11 4:57am
v5
Comments
Manfred Rudolf Bihy 29-Apr-11 10:55am    
Edit: Clarity and spelling improvements.
Henry Minute 29-Apr-11 11:58am    
I have looked at the question and the answers given so far.

They are pretty much what I would have advised. You do not appear to have stated why they would not work in your case and I am therefore not able to assist at this time.

Creating Windows Service is difficult. If you just need to run some application on schedule, such service is already created.

It is called Windows Task Scheduler, see http://en.wikipedia.org/wiki/Task_Scheduler[^].

I has its API you can use. You can use either v.1.0 or v.2.0.

You can use two applications bundled with Windows: AT.EXE (http://en.wikipedia.org/wiki/At_(Windows)[^]) or Schtasks.exe (http://en.wikipedia.org/wiki/Schtasks[^]). This approach does not require programming (well, maybe just a batch file because the command line is hard to remember).

—SA
 
Share this answer
 
Comments
Kim Togo 29-Apr-11 5:07am    
My 5. Good answer. Not "overkill" :-)
Sergey Alexandrovich Kryukov 29-Apr-11 10:10am    
Thank you, Kim.
--SA
Manas Bhardwaj 29-Apr-11 9:36am    
+5
Sergey Alexandrovich Kryukov 29-Apr-11 10:10am    
Thank you, Manas.
--SA
Joan M 29-Apr-11 10:17am    
5ed! probably it will be enough and it will be simpler to achieve than anything else...
My advice would be to create a Windows service that starts on machine startup. This Service would use a Timer to periodically check a database, or other form of data persistence(xml file, service config file, etc), for the time to execute your method. If the time elapses, then you execute the method.

Here is a good tutorial on Creating a Windows Service[^]

Hope this helps
 
Share this answer
 
Comments
Kim Togo 29-Apr-11 4:58am    
My 5. Good suggestion.
Sergey Alexandrovich Kryukov 29-Apr-11 5:04am    
Overkill! Please see my answer.
--SA
Sergey Alexandrovich Kryukov 29-Apr-11 5:04am    
This is overkill (even though it would work, can be good for something very advanced, maybe). OP really need Task Scheduler, hardly anything more than that.

Please see my answer.
--SA
Joan M 29-Apr-11 10:16am    
Possibly overkill... or not, this depends on the needs of the user, but a good suggestion... 5.
snake1 30-Apr-11 6:43am    
i have already created a windows service and it works good for me but i can't use timer in this case ,i want to execute a method every 1 minute but,the program execute it one time i have set the start type to Automatic so the windows service should start on windows startup but it just execute the method one time , the only way to execute the method again is to restart the service
As SA suggested you, the task scheduler can be used to set programs to run at a specific time. as you are looking for a code for this but the advantage of scheduling something with the AT command is that your program does not need to remain running on the system all of the time.
The task scheduler will start your program at the right time, it can execute and then it exits. You might need to tweak your program a little to have it backup automatically and then exit but that should be possible.
Actually How To Use the AT Command to Schedule Tasks[^]. AT command is much better for accomplished this task.
 
Share this answer
 
In my projects I have done this using Scheduler. Try with that its the exact way.
 
Share this answer
 
i don't understand your question?

Read guidelines before posting a question.

as per my understand your looking similar to this???[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Apr-11 5:05am    
Hard to say... maybe it's really simple thing?

Please see my answer, how I understand it.
--SA
Henry Minute 29-Apr-11 11:55am    
The question was simple enough to understand and compared to many in this forum was reasonably well written.

In any event it hardly deserves this kind of response.
Rajesh Anuhya 30-Apr-11 0:34am    
i answered it before editing. see there are 5 revisions. very first it was so complicated to understand me.
Ashutosh Tripathi 26-Jan-15 9:56am    
I am making a website in which i need to automatically call some method at 23:59 and update database. please help.
I am making a website in which i need to automatically call some method at 23:59 and update database. please help.
 
Share this answer
 
Comments
CHill60 26-Jan-15 10:11am    
If you have a question of your own then use the red "Ask a question" link at the top of the page. You will need to include far more detail that you have in this post - include the code that you are stuck with and explain your problem clearly. I suggest that you delete this post

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