I went every time for this and cannot understand what I am doing wrong. I am using the library Microsoft.Win32.TaskScheduler. Every time I look at the code, my task is always zero. 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();
}
}
}
}
}
Stored procedure SELECT ID FROM TABLE WHERE ID = @ID. The table has all mine ScheduledTaskswith an identifier assigned to each. However, the table saves them as "Task.job", so I delete the ".job". No matter what I do, t is always null, and I can understand why.
source
share