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

我怕爱的太早我们不能终老 提交于 2019-12-21 20:44:07

问题


I am trying to see if I can manage a bunch of windows scheduled tasks from an asp.net-mvc site (setting up new tasks, updating frequency of existing tasks, etc) because we want to allow non technical users to update this info (so we want to avoid people having to log into the webserver directly,etc)

I see you can do this from C# in general (links below) but not sure about entitlements, etc that would make it possible to manage via web app.

  • http://code.msdn.microsoft.com/windowsdesktop/CSTaskScheduler-2f70d723
  • Creating Scheduled Tasks

If its not possible from the web, are there other "remote" options so folks can do this without going in to specific box?


回答1:


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/




回答2:


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

    }
}


来源:https://stackoverflow.com/questions/19005691/is-it-possible-to-manage-windows-scheduler-from-an-asp-net-mvc-site-or-other-rem

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