Is it possible to manage windows scheduler from an asp.net-mvc site or other remote options?

我只是一个虾纸丫 提交于 2019-12-04 13:33:13

Yes you can, just use the taskschd.dll which can be found in C:\Windows\SysWOW64\ Just reference that to your web app and use it like this

using TaskScheduler;

namespace Test
{
    public class Class1
    {
        public void Test()
        {
            var taskService = new TaskScheduler.TaskScheduler();
            taskService.Connect();

            var rootFolder = taskService.GetFolder(@"\");

            var registeredTasks = rootFolder.GetTasks(0);
            foreach (var registeredTask in registeredTasks)
            {

            }
        }
    }
}

To prove to you its running here is screenshot of the running code called from a webpage

As you can see from my machine I grabbed 5 items from my task scheduler.

BTW I created a whole article for you in my blog on how to:

  1. Get All Scheduled Tasks
  2. Create/Update Scheduled Tasks
  3. Delete Scheduled Tasks

in here http://macaalay.com/2013/10/02/programmatic-management-of-scheduled-task/

I would rather to use Quartz.net, it looks more flexible to me rather than the windows task scheduler but the idea could work for both types of schedulers, Take a look to the following case to get the idea and maybe this helps you out:

  • Create a WCF
  • Consume the WCF service from your asp-net-mvc application
  • the WCF will have methods to perform common operations like add and remove tasks
  • Store the information for the task into a persistance storage (db, no-sql, xml, etc) or over your cache
  • You must have a JOB (from quartz) that reads the database and creates the tasks into the windows box, this job could run every x minutes or y hours
  • Use the information and perform a FIFO operation
  • Create a form in your asp-net-app for the users to input the tasks and the form will send the information to your wcf service

Edit: you need to have the following in mind: a wcf will give you the state you need to have an "state" to handle the web application tasks, quartz can handle the job to read the database and set up new tasks (quartz or windows scheduler) and the web form is just the front end to handle those operations.

setting up a job in quartz couls be as easy as:

public class ReadDBJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        // Do your work to read the database
        // and create the tasks that you need

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!