简体   繁体   中英

Method/Task scheduler c#

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?

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.

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.

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.

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)

If your application is always run, you can try with reactive extensions:

Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(x=>X());

Check here for more info https://msdn.microsoft.com/en-us/library/hh242977(v=vs.103).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM