Reputation: 611
I'm using C#.
I think thats a noob question but i'm try anyway.
I have a C# project with methods: X(),Y(),Z()
.
I'm looking for a task scheduler that run for me every day/every hour my methods (X(),Y(),Z()) at diffrent times.
What is the best way to do that?
Upvotes: 4
Views: 2454
Reputation: 2645
The easiest way is to use an existing library. Scott Hanselman had a blog on this a while back http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx.
Note: the article mentions asp.net however the schedulers are mentioned can also be run through console or Windows apps.
I personally use the Fluent scheduler (https://github.com/fluentscheduler/FluentScheduler) which has now been updated to support .net core. It's easy to use, and if you have simple scheduling requirements probably the one I'd recommend.
Upvotes: 3
Reputation: 2323
If your application is always run, you can try with reactive extensions:
Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(x=>X());
Check here for more infohttps://msdn.microsoft.com/en-us/library/hh242977(v=vs.103).aspx
Upvotes: 2
Reputation: 2470
I would make a windows service, and in the windows service you can call your methods with a timer check. (we did it so in our old company)
Upvotes: 1
Reputation: 34189
If you want to run some code every hour, every day or any other clearly known period, then the best option is to create a console application and use Windows Task Scheduler to run this application.
If this period is unclear and depends on some logics or calculations, then the best option is using always-running Windows Services which will run your methods when necessary.
Upvotes: 2
Reputation: 115691
Just make a console application that accepts a single parameter (think myapp.exe x
) that would call respective function. Then add a number of scheduled tasks to Windows Scheduler and you'll be all set.
Upvotes: 4