Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I don't know if anyone can answer this question but I am trying to figure out why I can not run an existing task with the new Task Scheduler. Here is my code:

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=@ID ", myConnection2);
                cmd2.Parameters.AddWithValue("@ID", txtTaskID.Text);

                SqlDataReader rdr;
                rdr = cmd2.ExecuteReader();

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        string task = rdr["TaskName"].ToString();
                        string newName = task.Remove(task.Length - 4, 4);
                        ScheduledTasks st = new ScheduledTasks();

                        Task t = st.OpenTask(newName);

                        if (t != null)
                        {
                            t.Run();
                        }
                        }




TaskName comes from my database. It shows up as TaskName.job, hence the remove statement. I have gone every where and no one can figure out why this will not work.
Posted
Updated 13-Jun-11 10:30am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900