在Windows任务计划程序C#计划任务 [英] Schedule task in Windows Task Scheduler C#

查看:142
本文介绍了在Windows任务计划程序C#计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要每天午夜的时间重新开始。对于这项工作,根据我的任务调度是使用了理想的事情,但我一直没能找到如何使用任务计划程序的API在C#(要使用没有外部库)

My application requires a re-start at midnight time daily. For this job, according to me, the task scheduler would be the ideal thing to use but I haven't been able to find how to use the Task Scheduler APIs in C# (no external libraries to be used)

在开始从任务计划程序完成后,我也想建议在一定的时间(即使在那个特定的时间应用程序可能没有响应,显示一些错误信息如何关闭应用程序自动框或由于某些问题的工作)

Once starting the application from Task Scheduler is done, I also wanted suggestions how to shutdown the application automatically at a certain time (even if the app at that particular time might be unresponsive, displaying some error message box or not working due to some problem)

推荐答案

好吧,我想你不知道有关 schtasks的命令。结果
你可以简单地打开一个命令提示符,然后键入的schtasks /?来查看可用选项。< BR>
这里所需要的一个是 /创建。当然,这个选项需要一系列参数来配置你的计划任务。但最终你能解决所有呼叫:

Well, I suppose you don't know about the schtasks command.
You could simply open a command prompt and type schtasks /? to see the options available.
The one needed here is /create. Of course this option requires a series of parameter to configure your scheduled task. But at the end you could resolve all calling:

Process.Start("schtasks", commandParams);

有关关闭过程的一部分,我使用了一个名为 pskill 的Sysinternals套件来自微软的Mark Russinovich的找到。这也可以设置为计划任务的批处理文件中被调用。

For the close process part, I use a little utility called pskill found in the Sysinternals suite from Microsoft's Mark Russinovich. Also this could be called inside a batch file set as scheduled task.

编辑:从psshutdown改为pskill(?您需要关闭只有您的应用程序右)

Changed from psshutdown to pskill (You need to close only your app right?)

这篇关于在Windows任务计划程序C#计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆