任务计划程序库的 C# 问题
为此我已经走遍了所有地方,但无法弄清楚我做错了什么。我正在使用 Microsoft.Win32.TaskScheduler 库。每次我单步执行代码时,我的任务总是为空。这是代码。
using (SqlConnection myConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
{
myConnection2.Open();
SqlCommand cmd2 = new SqlCommand("sp_GetProcessStart", myConnection2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@ID", txtTaskID.Text);
SqlDataReader rdr = cmd2.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
string task = rdr["TaskName"].ToString();
string newName = task.Remove(task.Length - 4, 4);
using (TaskService ts = new TaskService())
{
Task t;
t = ts.FindTask(newName);
if (t != null)
{
t.Run();
}
}
}
}
}
存储过程是SELECT ID FROM TABLE WHERE ID = @ID
。该表包含我的所有 ScheduledTasks
,并为每个任务分配了一个 ID。然而,该表将它们存储为“Task.job”,因此我删除了“.job”。无论我做什么,t 总是为空,我可以找出原因。
I have gone every where for this and can not figure out what I am doing wrong. I am using the Microsoft.Win32.TaskScheduler
library. Every time I step through the code, my task is always null. Here is the code.
using (SqlConnection myConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
{
myConnection2.Open();
SqlCommand cmd2 = new SqlCommand("sp_GetProcessStart", myConnection2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@ID", txtTaskID.Text);
SqlDataReader rdr = cmd2.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
string task = rdr["TaskName"].ToString();
string newName = task.Remove(task.Length - 4, 4);
using (TaskService ts = new TaskService())
{
Task t;
t = ts.FindTask(newName);
if (t != null)
{
t.Run();
}
}
}
}
}
The stored procedure is SELECT ID FROM TABLE WHERE ID = @ID
. The table has all of my ScheduledTasks
with an ID assigned to each. The table, however, stores them as "Task.job" so I am removing the ".job". No matter what I do, t is always null and I can figure out why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要删除 .job 扩展名。它只会找到带有 .job 扩展名的职位。
如果这不起作用尝试使用
Don't remove .job extention. It will find your jobs with .job extention only.
If that doesn't work out try using
我成功了。发现我没有拉入我的服务器变量,所以它不知道要运行什么任务。
I got it working. Come to find out I was not pulling in my server variable so it did not know what task to run.