Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: Can I use Microsoft.Win32.TaskScheduler.dll in web app(asp.net) for creating task scheduler

$
0
0
Hi
I would like to enquire about creating task scheduler with asp.net
Please kindly recommend me how to create task scheduler within web application with asp. net(C#).
I try testing by the following codes in console application. It is great.
using Microsoft.Win32.TaskScheduler;
static void Main(string[] args)
        {
            using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "My first PurgeApplication task scheduler";

                DateTime start = DateTime.Now.AddMinutes(1);
                td.Triggers.Add(new TimeTrigger() { StartBoundary = start });

                string path = @"C:/inetpub/wwwroot/AppManageWindowScheduler/exe/PurgeApplication.exe";

                td.Actions.Add(new ExecAction(path, null, null));
                ts.RootFolder.RegisterTaskDefinition("My first parallell task scheduler", td);
            }
        }
However, I try testing in web app instead. It occur error.
http://localhost/AppManageWindowScheduler/Default.aspx
using Microsoft.Win32.TaskScheduler;
protected void Page_Load(object sender, EventArgs e)
    {
        CreateTaskRunOnce();
    }
    private void CreateTaskRunOnce()
    {
        using (TaskService ts = new TaskService())
        {
            TaskDefinition td = ts.NewTask();
            td.RegistrationInfo.Description = "My first PurgeApplication task scheduler";

            DateTime start = DateTime.Now.AddMinutes(1);
            td.Triggers.Add(new TimeTrigger() { StartBoundary = start });

           // string path = @"C:/inetpub/wwwroot/AppManageWindowScheduler/exe/PurgeApplication.exe";
            string path = Server.MapPath("~/exe/PurgeApplication.exe");

            td.Actions.Add(new ExecAction(path, null, null));
            ts.RootFolder.RegisterTaskDefinition("My first parallell task scheduler", td);
        }
    }
I suspect that error may occur from “string path = Server.MapPath("~/exe/PurgeApplication.exe");” .

Could you please suggest me to what is good solution for resolving this?
I indeed need to create task scheduler through asp.net web site.
For given error , please see below.
(38,4):Task:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: (38,4):Task:

Source Error:

Line 30:
Line 31: td.Actions.Add(new ExecAction(path, null, null));
Line 32: ts.RootFolder.RegisterTaskDefinition("My first parallell task scheduler", td);
Line 33: }
Line 34: }

Source File: c:\inetpub\wwwroot\AppManageWindowScheduler\Default.aspx.cs Line: 32

Stack Trace:

[COMException (0x80041318): (38,4):Task:]
Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl) +0
Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl) +237
Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition) +284
_Default.CreateTaskRunOnce() in c:\inetpub\wwwroot\AppManageWindowScheduler\Default.aspx.cs:32
_Default.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\AppManageWindowScheduler\Default.aspx.cs:16
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178

Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>