System.InvalidCastException was unhandled
HResult=-2147467262
Message=Specified cast is not valid.
Source=Microsoft.Win32.TaskSchedulerEditor
StackTrace:
at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.taskMultInstCombo_SelectedIndexChanged(Object sender, EventArgs e)
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
I'm calling the UI Dialog as follows:
Microsoft.Win32.TaskScheduler.Task dct = null;
try
{
dct = util.CreateTask();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
if (dct != null)
{
TaskEditDialog ted = new TaskEditDialog(dct, true, true);
try { ted.ShowDialog(); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
Windows 10 Professional. Visual Studio 2012. Nuget packages installed Sep 2015. Any assistance gratefully received.
Comments: ** Comment from web user: DonAtVega **
I create the Task if it's not there like so
```
TaskService tsmgr = new TaskService();
Microsoft.Win32.TaskScheduler.Task dct = tsmgr.FindTask(strings.DataCommunicator2Task, true);
if (dct == null)
{
string strThisProgram = Assembly.GetEntryAssembly().CodeBase.ToString();
strThisProgram = strThisProgram.Replace(@"file:///", @"");
strThisProgram = strThisProgram.Replace('/', '\\');
TaskDefinition td = tsmgr.NewTask();
td.Settings.AllowDemandStart = true;
//td.Settings.RunOnlyIfLoggedOn = false;
td.RegistrationInfo.Description = strings.ExecuteTheDataCommunicator;
DateTime dt2 = DateTime.Now;
dt2 = dt2.AddHours(2);
TimeTrigger tg = new TimeTrigger();
tg.Enabled = true;
tg.StartBoundary = dt2;
tg.Repetition.Interval = TimeSpan.FromMinutes(5);
td.Triggers.Add(tg);
td.Actions.Add(new ExecAction(strThisProgram, null, null));
try
{
tsmgr.RootFolder.RegisterTaskDefinition(strings.DataCommunicator2Task, td);
dct = tsmgr.FindTask(strings.DataCommunicator2Task, true);
}
catch
{
MessageBox.Show(strings.CouldNotCreateDataCommunicatorTask);
dct = null;
}
}
return dct;
```
So I guess those will be the default values? Until you edit them...