Unable to initialize a TaskEditDialog object

Jun 30, 2010 at 8:35 PM
Edited Jul 1, 2010 at 3:56 PM

Hello,
I found taskscheduler very useful but I'm having real hard-time trying to use the TaskschedulerEditor.
I"m using XP SP3 32 bits and following the example posted here in the examples page:

// Get the service on the local machine
using (TaskService ts = new TaskService())
{
   // Create a new task
   const string taskName = "Test";
   Task t = ts.AddTask(taskName,
      new TimeTrigger() { StartBoundary = DateTime.Now + TimeSpan.FromHours(1), Enabled = false },
      new ExecAction("notepad.exe", "c:\\test.log", "C:\\"));

   // Edit task and re-register if user clicks Ok
   TaskEditDialog editorForm = new TaskEditDialog();
   editorForm.Editable = true;
   editorForm.Initialize(t);
   if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
   {
      ts.RootFolder.RegisterTaskDefinition(taskName, editorForm.TaskDefinition);
   }

   // Remove the task we just created
   ts.RootFolder.DeleteTask(taskName);
}



and   

editorForm.Initialize(t)

gives me this error:

-----------------------------------------------------------------------------------------------------------------------------------
System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="Microsoft.Win32.TaskScheduler"
  StackTrace:
       at Microsoft.Win32.TaskScheduler.TaskService.ShouldSerializeUserName()
       at Microsoft.Win32.TaskScheduler.TaskService.get_UserName()
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.set_TaskDefinition(TaskDefinition value)
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.set_Task(Task value)
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.Initialize(Task task)
       at Microsoft.Win32.TaskScheduler.TaskEditDialog.Initialize(Task task)
       at test_taskeditor.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\My Documents\Visual Studio 2008\Projects\Testes\test_taskeditor\test_taskeditor\Form1.cs:line 37
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at test_taskeditor.Program.Main() in C:\Users\Administrator\My Documents\Visual Studio 2008\Projects\Testes\test_taskeditor\test_taskeditor\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

----------------------------------------------------------------------------------------------------------------------------------------------
By the way, I'm referencing Microsoft.Win32.TaskSchedulerEditor; as well and I'm able to do editorForm.Show() but it seems that the Task t lacks the UserAccountDomain. Look:

Image and video hosting by TinyPic

I"m using the1.5 Beta 2 release .

Thanks in advance...

Jose Luis

 

Jul 1, 2010 at 11:13 PM

Found the solution myself:

When instantiating a new taskService, I had to pass in the constructor: username, accountDomain, password and forceV1 = true

 

 

 

Coordinator
Jul 4, 2010 at 3:27 PM

There was actually a bug in the Beta 2 release that caused this failure. Try the 1.5 Beta 3 code and remove the changes you made to the TaskService constructor.

Jul 6, 2010 at 10:32 PM

Thanks for a quick reply Dahall, it is ok now :)