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

System.IO.FileNotFoundException while trying to read Task.LastTaskResult property

Feb 23, 2010 at 10:26 AM

Hi,

I am getting an error while trying to read Task.LastTaskResult information. This happens only in the case where task Status is "Could not start". Also the Task.Status property is showing "Ready" instead of "Could not start" (this message is from %WINDIR%\TASKS folder).

I am using Windows Server 2003, x64 Edition, SP2

Error message:

LastTaskResult' threw an exception of type 'System.IO.FileNotFoundException'    int {System.IO.FileNotFoundException}{"The system cannot find the file specified. (Exception from HRESULT: 0x80070002)":null}

Following is the stack trace (nothing much):

at Microsoft.Win32.TaskScheduler.V1Interop.ITask.GetExitCode()
   at Microsoft.Win32.TaskScheduler.Task.get_LastTaskResult()
   at DSS.TaskScheduler.GetJob(String name) in xxxxxxx.cs:line 57
   at DSSTest.Program.Test_GetJob() in xxxxxxxxx.cs:line 116
   at DSSTest.Program.Main(String[] args) in xxxxxxxxxx.cs:line 17
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

 

The only way I can handle this is by using try-catch. Please let me know if there is something I am missing here.

Thanks,

Gopala

Coordinator
Feb 23, 2010 at 3:14 PM

First of all, the FileNotFoundException that is being thrown is from the Microsoft library and I don't know why. The documentation says the ITask.GetExitCode() method is supposed to return 0 if the task has never been started. You will need to catch the exception in your code. Sorry.

On your Status descrepancy, that one is my doing. Version 2.0 of the library from Microsoft reduced the status states dramatically. Below is the code that I used to dumb-down the 1.0 codes to 2.0 values. Let me know if you think I mis-categorized them.

switch (v1Task.GetStatus())
{
    case V1Interop.TaskStatus.Ready:
    case V1Interop.TaskStatus.NeverRun:
    case V1Interop.TaskStatus.NoMoreRuns:
    case V1Interop.TaskStatus.Terminated:
        return TaskState.Ready;
    case V1Interop.TaskStatus.Running:
        return TaskState.Running;
    case V1Interop.TaskStatus.Disabled:
        return TaskState.Disabled;
    case V1Interop.TaskStatus.NotScheduled:
    case V1Interop.TaskStatus.NoTriggers:
    case V1Interop.TaskStatus.NoTriggerTime:
    default:
        return TaskState.Unknown;
}