使用dateTimePicker值设置计划任务
我已经在 Visual Studio 中创建了一个 Windows 窗体,
我希望能够使用用户从 dateTimePicker 中选择的值来运行计划任务。
因此,一旦用户选择了他们希望 .exe 运行的日期和时间,我需要将其设置为计划任务。
我已经重新研究了如何以编程方式运行 Windows 调度程序,并发现有使用 Taskscheduler
的选项,但我使用的是 3.5 并且该程序集不可用?
我有办法做到这一点吗?
提前致谢。
I have created a windows form in Visual Studio,
I want to be able to run a scheduled task using the users selected value from the dateTimePicker.
So once the user has selected the date and time they wish the .exe to run, I need this to be set as a scheduled task.
I have reaserched how to run windows scheduler programatically and found that there is options using Taskscheduler
but I am using 3.5 and this assembly is not available?
Is there a way I can do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TaskScheduler
类是 System.Threading.Tasks 命名空间的一部分。您必须首先通过在类中执行using System.Threading.Tasks;
来引用它。然后,您可以参考这些示例代码了解如何使用
任务计划程序
。The
TaskScheduler
class is part of theSystem.Threading.Tasks
namespace. You have to reference it first by doing ausing System.Threading.Tasks;
in your class.You can then refer to these sample codes on how to use the
TaskScheduler
.如果您无法通过任何方式访问TaskScheduler,您可以自己创建一个Windows服务来执行此调度。您可以将用户选择的值转储到文件、注册表或其他任何内容,然后使用您的服务读取该值并触发一个计时器,该计时器在 ValueReadFromFile - DateTime.Now 间隔内自行重置。
诸如此类,天真地说。
忘了说:显然,一旦计时器到期,您将使用该 EXE 创建并启动一个进程。
If you don't have access to TaskScheduler by whatever means, you can create a windows service by yourself to do this scheduling. You would dump the value picked by users to a file, registry or whatever, then read that value with your service and fire a timer that resets itself in the interval ValueReadFromFile - DateTime.Now.
Something like that, naively speaking.
Forgot to say: obviously, you would create and launch a process with that EXE once the timer elapses.