在.Net中设置计划任务

时间:2022-04-29 02:22:38

I've read a few posts here on * about task scheduling, but I'm not sure that I get it right. I'm coding (in VB.Net) a backup application, that I'd like to add as a scheduled task (in fact, I'd just like to let the user decide to run it every day at, for example, 3 AM).

我在*上阅读了一些关于任务调度的帖子,但我不确定我是否正确。我正在编写(在VB.Net中)一个备份应用程序,我想将其添加为计划任务(事实上,我只想让用户决定每天运行它,例如,3上午)。

I've read posts suggesting to use a windows service for this, but it sounds a bit to much for something as simple as periodically running a task, isn't it?

我已经阅读了建议使用Windows服务的帖子,但对于像定期运行任务这样简单的事情听起来有点太多了,不是吗?

Could you please advise me on how to simply set a scheduled task in VB.Net? I'm trying to keep my code as lightweight as possible.

你能告诉我如何在VB.Net中设置一个预定的任务吗?我试图让我的代码尽可能轻量级。

2 个解决方案

#1


4  

The best thing is to not write a scheduler, but use the built-in Windows scheduler to run your code.

最好的办法是不编写调度程序,而是使用内置的Windows调度程序来运行代码。

More info:

更多信息:

http://support.microsoft.com/kb/308569

http://support.microsoft.com/kb/308569

Note: if you schedule a task to run under an account other than your own, the application may not have access to network drives or some other resources. In other words, there may be some security challenges to work through, particularly for something like a backup app.

注意:如果您安排任务在您自己以外的帐户下运行,则该应用程序可能无法访问网络驱动器或其他一些资源。换句话说,可能会遇到一些安全挑战,特别是对于像备份应用程序这样的东西。

If this is just a personal app for backup, my recommendation would be to use XCOPY from a batch file rather than re-inventing the wheel.

如果这只是一个备份的个人应用程序,我的建议是从批处理文件中使用XCOPY而不是重新发明*。

#2


1  

As RichardTallent says, don't write your own; instead hook into the Windows scheduler. It's not too difficult.

正如RichardTallent所说,不要自己写;而是挂钩到Windows调度程序。这不是太困难。

We used the libraries and examples here and here. Easy to use. Kudos to Eduardo Morcillo and Eric Moreau for showing the way.

我们在这里和这里使用了库和示例。使用方便。感谢Eduardo Morcillo和Eric Moreau展示自己的方式。

#1


4  

The best thing is to not write a scheduler, but use the built-in Windows scheduler to run your code.

最好的办法是不编写调度程序,而是使用内置的Windows调度程序来运行代码。

More info:

更多信息:

http://support.microsoft.com/kb/308569

http://support.microsoft.com/kb/308569

Note: if you schedule a task to run under an account other than your own, the application may not have access to network drives or some other resources. In other words, there may be some security challenges to work through, particularly for something like a backup app.

注意:如果您安排任务在您自己以外的帐户下运行,则该应用程序可能无法访问网络驱动器或其他一些资源。换句话说,可能会遇到一些安全挑战,特别是对于像备份应用程序这样的东西。

If this is just a personal app for backup, my recommendation would be to use XCOPY from a batch file rather than re-inventing the wheel.

如果这只是一个备份的个人应用程序,我的建议是从批处理文件中使用XCOPY而不是重新发明*。

#2


1  

As RichardTallent says, don't write your own; instead hook into the Windows scheduler. It's not too difficult.

正如RichardTallent所说,不要自己写;而是挂钩到Windows调度程序。这不是太困难。

We used the libraries and examples here and here. Easy to use. Kudos to Eduardo Morcillo and Eric Moreau for showing the way.

我们在这里和这里使用了库和示例。使用方便。感谢Eduardo Morcillo和Eric Moreau展示自己的方式。