Hi,
How can I execute some code, once a day. e.g. call MyMethod() at 3pm every day. (provided the app is running of course)...
Im trying to do this in c# winforms.
Hi,
How can I execute some code, once a day. e.g. call MyMethod() at 3pm every day. (provided the app is running of course)...
Im trying to do this in c# winforms.
If you simply want to run something at the same time every day, you can use the built in task scheduler.
You can setup a daily schedule that will execute your application at the same time every day.
Otherwise, in your application you will need to setup a timer and check in the tick event if the current time is 3pm and only call your method at that point.
I would have suggested a windows service, but as you stated that you only need the method to run if the application is already running, this is not needed.
Windows Service and a Timer!
check out codeproject's simple windows server:
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
Or if you want more control you can create a Windows Service. Simply inherit from System.ServiceProcess.ServiceBase and add a timer on the OnStart override. Install your windows service on the machine.
The task scheduler is the best option. If you need to do it inside a .NET application there is no component that allows you to trigger an event at a specific time. But you can set up a Timer to raise an event every minute (for example, but you can set up a smaller o bigger interval depending on your needs), then in the handler you check the current time and if it is 3pm you can execute your code, else do nothing.