English 中文(简体)
C# 任务表 三叉 not
原标题:C# Task Scheduler Trigger not working

我不知道谁能帮助这样做,但我是在我提出申请时发现一个错误(不提及某一物体的情况)。 该守则是:

using (SqlConnection myConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
            {
                myConnection2.Open();
                SqlCommand cmd2 = new SqlCommand("SELECT ID, TaskName, Permission from ScheduledTasks s, Roles r WHERE s.ID= " + txtTaskID.Text, myConnection2);

                SqlDataReader rdr;
                rdr = cmd2.ExecuteReader();

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        string task = rdr["TaskName"].ToString();
                        Trigger tg = new RunOnceTrigger(DateTime.Now);
                        ScheduledTasks st = new ScheduledTasks();
                        Task t = st.OpenTask(task);
                        t.Triggers.Add(tg);
                        t.Save();
                    }
                }
            }

它错误出现在Triggers.Add(tg)行文中。 我已经通过该守则,而现在的任务是储存正确的任务名称。 它刚刚赢得这项任务。

问题回答

我的直接猜测是,<代码>t.Triggers目前等于null

You may need to instantiate a Triggers Collection in t.Triggers before trying to add anything to it.

似乎你正在使用提交人所展示的方式。 你的错误是什么? 请发出例外信息。

From the authors FAQ:

为什么我获得例外?

This problem usually comes up for clients who want to use the Task Scheduler from ASP.NET code. Ordinarily, such code runs in the ASPNET account which has rather low privilege and can t use the Task Scheduler. The solution to this is to set your code to run in another, more privileged account. This is called impersonation, and you can set it up in your web.config file.

The Task Scheduler doesn t require the client to run with administrative privilege, but if it s not, there will be restrictions on what can be done. I haven t found these to be well-documented. However, until recently it seemed that non-administrators could see and manipulate the tasks they created, but no others. In Windows XP SP2, there seems to be some generalization. In the Explorer, there is a new Security tab on the task Properties dialog box. There is also do a little documentation explaining that the file permissions on the task will govern what other users can do with them. Read = look at it, Read/Execute = run the task, Write = modify the task.

我也想知道,你打算为任务所要完成的任务提供任何细节。 如同应该发生的情况一样,有些方案需要执行,而任务要执行。 我假定,你在张贴之前就删除了这些内容。 否则,也许本图书馆会无意在未提供资料说明申请在预定时间执行的情况下创造任务。

我使用这一特别图书馆:http://tasksdateduler.codeplex.com/。 ......其积极发展,最新版本已于上月公布,可能的话。 它自动使用根据本组织编制的工作队时间表的适当版本。 它只是个人的偏爱......





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签