I've had a long standing problem where the TaskScheduler.TaskService.FindTask method sometimes return a reference to a task, even though the task does not exist.
Note that the task with the given name has existed at some point, but it has been removed since (using TaskScheduler.TaskService.DeleteTask).
Sometimes there is still a reference in the registry to the old task, but removing it from the registry does not resolve it. Somehow the FindTask() still thinks it exists.
TaskService ts;
var try1 = ts.FindTask("dummy");
var try2 = ts.FindTask("test1");
At this moment, both commands above will return a reference to a task, even though only 1 of them exists.
Checking a property like try1.Enabled returns true, but try1.State gives an error:
Value does not fall within the expected range
So to resolve I can probably do a try-catch to determine if this is a real or fake task. The problem is that I cannot create a new task with the given name if the TaskService class thinks it exists.
Any one with a suitable solution?