In the process of deploying our .net app, I've got about 20 scheduled tasks set up on a server, all of which basically do the same thing: invoke a small .net console app that pulls data from a SQL db and posts it to a web service. Each task invokes a separate copy of the app, each copy having a different lookup ID value in its config file.
在部署我们的.net应用程序的过程中,我在服务器上设置了大约20个计划任务,所有这些任务基本上都做同样的事情:调用一个小的.net控制台应用程序,从SQL数据库中提取数据并发布它到网络服务。每个任务都会调用应用程序的单独副本,每个副本的配置文件中都有不同的查找ID值。
All but two of these tasks run reliably every night. Two of the tasks seem to sporadically stop running from time to time, and it's currently a mystery as to why. When they stop running, the scheduled task interface correctly shows their last run date, which is a day or more behind the other tasks, which have continued to run at the scheduled time. The tasks which stopped running do not run again on their own, despite being indicated as scheduled to run every night. There are no errors recorded in the event log or in the scheduled task interface itself. And here's the strangest part to us: If I manually kick off the scheduled task, it runs fine, it invokes the .net console app and everything finishes without anomaly. And then it continues to run fine at its scheduled time, for days or weeks at a time, only to eventually fail, seemingly out of the blue. It appears both tasks always start to fail on the same night.
除了其中两项任务外,其他所有任其中两项任务似乎偶尔不时地停止运行,而且目前对于原因来说这是个谜。当它们停止运行时,计划任务界面会正确显示其上次运行日期,这是其他任务的一天或更多天,这些任务在预定时间继续运行。尽管被指示按计划每晚运行,但停止运行的任务不会自行运行。事件日志或计划任务界面本身没有记录错误。这是我们最奇怪的部分:如果我手动启动计划任务,它运行正常,它会调用.net控制台应用程序,一切都没有异常完成。然后它在预定的时间继续运行,一次持续数天或数周,但最终失败,似乎是突然之间。似乎两个任务总是在同一个晚上开始失败。
8 个解决方案
#1
There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.
有一个“最后结果”列应该为您提供与任务本身运行相关的代码(它不会有任何类型的异常数据)。 0表示任务已完成且没有错误。您还可以查看其他任何内容,看看为什么任务无法启动。如果任务似乎仍未运行,但您仍然看到最后结果为0,这意味着您的代码中存在某些内容,但它正在优雅地退出。
#2
Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit. If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:
Taskscheduler在64位系统上假设应用程序是64位。如果它是从32位命令行32位启动它,即如果你想运行c:\ program files(x86)\ Myprogram \ Program.exe,告诉taskscheduler启动:
- %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
%systemroot%\ Syswow64 \ cmd.exe / C“c:\ program files(x86)\ Myprogram \ Program.exe”
This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.
这迫使它从32位命令提示符启动,因此使用32位仿真。
#3
Did you set "Start in" property?
你有没有设置“开始”属性?
If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!
如果这些.NET控制台应用程序需要app.config或其路径中的某些文件,则必须将“Start in”属性设置为“c:\ your \ app \ path \”,否则它们就像它们位于系统目录中一样,他们找不到他们需要的文件!
#4
One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:
将计划任务与无密码的Windows用户帐户关联时,会发生计划任务未运行的一个原因:默认情况下,禁止使用空密码运行计划任务。如果要从没有密码的帐户运行计划任务,则必须禁用系统变量:
- Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
- Select: "Accounts: Limit local account use of blank passwords to console logon only"
- Disable this variable
转至:开始>管理工具>本地安全策略>安全设置>本地策略>安全选项
选择:“帐户:限制本地帐户使用空白密码仅限控制台登录”
禁用此变量
Disclaimer: It´s not recommended to have accounts with no password.
免责声明:不建议没有密码的帐户。
#5
In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.
就我而言,即使表示上次运行成功(0),计划任务也不会运行。事实证明,正在运行作业的Windows用户帐户已被锁定。我只是意识到这一点,因为我尝试编辑现有的计划任务,将用户帐户设置为同一个,然后点击确定,它给我一个关于被锁定帐户的错误。
#6
Maybe they hung and were still running?
也许他们挂了,还在跑?
You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner
您可以单击extras菜单并选择菜单条目以查看日志,然后记事本将从任务计划程序打开一个日志文件
#7
I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558
当我试图解决一个行为不端的计划任务时,我发现此页面很有用:http://support.microsoft.com/kb/308558
Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
选择View-> Details以显示其他信息,如Last Run Time和Status,这个页面给了我状态/错误代码的含义:http://msdn.microsoft.com/en-us/library/windows /desktop/ms681381(v=vs.85).aspx
#8
The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only one possible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):
以下SO问题的答案也可能与阅读此问题的人高度相关(但是,NB,它仅描述了计划任务的一个可能的特定问题,我相信这些问题都不是另一个的重复):
为什么我的计划任务正确更新其“上次运行时间”,并给出“(0x0)”的“上次运行结果”,但仍然没有实际工作?
The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.
给出另一个问题的答案摘要是Windows 2012计划任务没有为任务设置为运行的帐户看到正确的环境变量,包括PATH。
In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt
in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.
就更一般的计划任务故障排除而言(如本问题中所述),您可以测试此特定问题(例如,在该任务中运行SET> test.txt,如该答案中所建议的),并且一旦您看到它发生,如果影响你,你可以解决它。
#1
There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.
有一个“最后结果”列应该为您提供与任务本身运行相关的代码(它不会有任何类型的异常数据)。 0表示任务已完成且没有错误。您还可以查看其他任何内容,看看为什么任务无法启动。如果任务似乎仍未运行,但您仍然看到最后结果为0,这意味着您的代码中存在某些内容,但它正在优雅地退出。
#2
Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit. If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:
Taskscheduler在64位系统上假设应用程序是64位。如果它是从32位命令行32位启动它,即如果你想运行c:\ program files(x86)\ Myprogram \ Program.exe,告诉taskscheduler启动:
- %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
%systemroot%\ Syswow64 \ cmd.exe / C“c:\ program files(x86)\ Myprogram \ Program.exe”
This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.
这迫使它从32位命令提示符启动,因此使用32位仿真。
#3
Did you set "Start in" property?
你有没有设置“开始”属性?
If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!
如果这些.NET控制台应用程序需要app.config或其路径中的某些文件,则必须将“Start in”属性设置为“c:\ your \ app \ path \”,否则它们就像它们位于系统目录中一样,他们找不到他们需要的文件!
#4
One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:
将计划任务与无密码的Windows用户帐户关联时,会发生计划任务未运行的一个原因:默认情况下,禁止使用空密码运行计划任务。如果要从没有密码的帐户运行计划任务,则必须禁用系统变量:
- Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
- Select: "Accounts: Limit local account use of blank passwords to console logon only"
- Disable this variable
转至:开始>管理工具>本地安全策略>安全设置>本地策略>安全选项
选择:“帐户:限制本地帐户使用空白密码仅限控制台登录”
禁用此变量
Disclaimer: It´s not recommended to have accounts with no password.
免责声明:不建议没有密码的帐户。
#5
In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.
就我而言,即使表示上次运行成功(0),计划任务也不会运行。事实证明,正在运行作业的Windows用户帐户已被锁定。我只是意识到这一点,因为我尝试编辑现有的计划任务,将用户帐户设置为同一个,然后点击确定,它给我一个关于被锁定帐户的错误。
#6
Maybe they hung and were still running?
也许他们挂了,还在跑?
You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner
您可以单击extras菜单并选择菜单条目以查看日志,然后记事本将从任务计划程序打开一个日志文件
#7
I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558
当我试图解决一个行为不端的计划任务时,我发现此页面很有用:http://support.microsoft.com/kb/308558
Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
选择View-> Details以显示其他信息,如Last Run Time和Status,这个页面给了我状态/错误代码的含义:http://msdn.microsoft.com/en-us/library/windows /desktop/ms681381(v=vs.85).aspx
#8
The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only one possible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):
以下SO问题的答案也可能与阅读此问题的人高度相关(但是,NB,它仅描述了计划任务的一个可能的特定问题,我相信这些问题都不是另一个的重复):
为什么我的计划任务正确更新其“上次运行时间”,并给出“(0x0)”的“上次运行结果”,但仍然没有实际工作?
The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.
给出另一个问题的答案摘要是Windows 2012计划任务没有为任务设置为运行的帐户看到正确的环境变量,包括PATH。
In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt
in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.
就更一般的计划任务故障排除而言(如本问题中所述),您可以测试此特定问题(例如,在该任务中运行SET> test.txt,如该答案中所建议的),并且一旦您看到它发生,如果影响你,你可以解决它。