如何在c#中结束Windows XP中的任务计划程序任务 [英] How do I End the Task Scheduler Task in Windows XP in c#
问题描述
您好b $ b
我正在开发一个在Windows XP中创建任务的应用程序。
我已经按照下面的链接中给出的步骤而且我也可以触发任务。
http://pavanarya.wordpress.com/tag/microsoft-win32/ [ ^ ]
但我不知道怎么做在结束时间结束任务..
这是我的代码
使用(TaskService ts = new TaskService())
{
//创建一个新的任务定义并分配属性
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description =打开记事本;
//创建一个触发器,立即触发任务
触发器tg =触发器。 CreateTrigger(TaskTriggerType.Time);
tg.StartBoundary = DateTime.Now.AddMin utes(1);
//tg.EndBoundary = DateTime.Now.AddMinutes(2);
td.Triggers.Add(tg);
string cal_time = tg.StartBoundary.ToString(HH:m:s);
string en_time = tg.EndBoundary.ToString(HH:m:s);
TimeSpan duration = DateTime.Parse(en_time).Subtract(DateTime.Parse(cal_time));
//创建一个将启动记事本的动作每当触发器触发
td.Actions.Add(new ExecAction(notepad.exe,null,null));
/ /在根文件夹中注册任务
ts.RootFolder.RegisterTaskDefinition(@Test,td);
}
请帮助
Hi
I am developing an application to create a Task in Windows XP.
I have followed the steps given in link below And also I am able to trigger the task.
http://pavanarya.wordpress.com/tag/microsoft-win32/[^]
But I am not sure how to End the task after the End time..
Here is my code
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Open Notepad";
// Create a trigger that will fire the task now
Trigger tg = Trigger.CreateTrigger(TaskTriggerType.Time);
tg.StartBoundary = DateTime.Now.AddMinutes(1);
//tg.EndBoundary = DateTime.Now.AddMinutes(2);
td.Triggers.Add(tg);
string cal_time = tg.StartBoundary.ToString("HH:m:s");
string en_time = tg.EndBoundary.ToString("HH:m:s");
TimeSpan duration = DateTime.Parse(en_time).Subtract(DateTime.Parse(cal_time));
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", null, null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
}
Please Help
推荐答案
您可以终止该过程 - 示例 [ ^ ]。
尝试处理Process.GetProcessesByName,杀死进程和退出事件 [ ^ ]。
You can kill the process - Example[^].
Try Process Process.GetProcessesByName, Kill Process and Exit Event [^] as well.
这篇关于如何在c#中结束Windows XP中的任务计划程序任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!