Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

Commented Issue: Exception when editing a Task [12239]

$
0
0
I'm getting this when editing a Task and trying to change the behaviour if the Task is already running.

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...


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>