This project has moved. For the latest updates, please go here.

GetTask for testing existence of task

Sep 25, 2009 at 4:14 PM

I'm running this code on XP (so, V1), and when I try using GetTask to check for a task before I try deleting it, I get a FileNotFoundException from the low-level interop instead of null coming back. Not sure what the intended behaviour is, but peeking at the source I'm not clear if the internal exception bubbling up is the intended behaviour. I suspect returning null makes things more consistent between v2 and v1...but I know nothing about this area so I'll go with whatever you prefer :)

Sep 26, 2009 at 11:04 AM

It's a bug. (see: http://taskscheduler.codeplex.com/WorkItem/View.aspx?WorkItemId=4328 )

You can solve with this code that I used in my project:

 

TaskService taskService = new TaskService();
TaskFolder tasksFolder = taskService.GetFolder(@"\");
TaskCollection listOfTasks = tasksFolder.Tasks;

try
{
     Task theTask = listOfTasks[nameOfTask];
     //now you can use "theTask"
     //...
}
catch (System.IO.FileNotFoundException ex) 
{
     MessageBox.Show(ex.ToString());
}

 

 

Sep 26, 2009 at 11:07 AM

Where "nameOfTask" is the name of the task that you want find.

 

In Windows Vista/7 the GetTask method runs very well instead.

 

Coordinator
Sep 30, 2009 at 3:19 AM

This issue has been fixed as of code drop 30714 and will be in the released build 1.4.1.