How to set up a schedule for working with the .NET platform?

How can I do simple job scheduling using C # /. NET?

Suppose I have a method (of a specific class) that I want to run automatically daily, hourly, weekly, etc.

Is there an easy way to do this?

+4
source share
2 answers

There are three ways to do this in .net

1) create a windows service. If in the windows (assuming you are on windows 7), you click the "Start" button and type "view local services" and then click on the result, all you see here is a Windows service. When you encode a Windows service, it is basically a console application, enclosed in code that installs the service and sets the scheduling time. There are many guides to building a Windows service. Here is the Microsoft manual: http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx

2) Create an exe application, and then enter Task Scheduler. Click the "Start" button again and find "Task Scheduler." This differs from the Windows service in that you manage scheduling from the task scheduler, and not in your application. In addition, earlier it was necessary to restart the scheduled tasks at reboot, where, when Windows services can start when the operating system starts (I'm not sure that this rule still applies, I have not used the task scheduler for some time). Here is Microsoft's guide on how to do this: http://windows.microsoft.com/en-GB/windows7/schedule-a-task

3) You can also check out Quartz.NET, which is an enterprise-level job scheduling platform. I have used it several times and it works very well. Quartz.NET can be found here: http://quartznet.sourceforge.net/

Another thing you might want to pay attention to is Topshelf. This simplifies the development of the Windows service: http://topshelf-project.com . I have not used it myself, but I know many people who have and recommend it.

Edit after more details added to the question

If you are looking for a way that you can call a method in a class using some kind of cron equivalent, there is no way to do this. You need to make this cool part of the application (exe) and then use one of the above methods to plan the execution of this exe.

The fastest and easiest way (not necessarily the best depending on the needs of your application) is to create a simple console application ( http://msdn.microsoft.com/en-us/library/ms438026(v=office.14).aspx ). Copy the class you are talking about, and then call the method that you want to schedule in the main application method. Then use the task scheduler as described above.

Hope this helps.

+10
source

If you have an ASP.NET application, the easiest way is for the Windows Task Scheduler to call a special URL in your application using curl.exe .

Windows Task Scheduler can also be used to run a custom EXE.

+1
source

All Articles