private void BtnCreate_Click(object sender, EventArgs e) { try { TaskSchedulerUnit.CreateTaskScheduler("user", TaskName, AutoRoot, (int)nupMintue.Value, DateTime.MinValue, DateTime.MinValue, false, "自动更换桌面"); MessageBox.Show("创建完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 获取任务 /// </summary> private void LoadTaskInfo() { nupMintue.Minimum = 1; nupMintue.Maximum = 43200; try { IRegisteredTask task = TaskSchedulerUnit.FindTask(TaskName); if (task == null) { return; } foreach (ITrigger tir in task.Definition.Triggers) { string time = tir.Repetition.Interval; TimeSpan ts = TaskSchedulerUnit.GetTimeSpan(time); nupMintue.Value = (int)ts.TotalMinutes; break; } }catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }