简体   繁体   English

任务计划程序/ PowerShell /超时

[英]Task scheduler / powershell / timeout

I have a website which I need to run a script every hour. 我有一个网站,我需要每小时运行一个脚本。 I set these parameters on task scheduler and it seems to work. 我在任务计划程序上设置了这些参数,它似乎可以正常工作。

Program/script: powershell.exe 程序/脚本:powershell.exe

Add arguments: -c (new-object system.net.webclient).downloadstring(' http://www.example.com/test.ashx ') 添加参数:-c(new-object system.net.webclient).downloadstring(' http://www.example.com/test.ashx ')

The problem is that I have a big loop and processes in this script and the script stops before it finish the loop! 问题是我在此脚本中有一个很大的循环和进程,脚本在结束循环之前就停止了! Is there any possibility to add a timeout as an argument or something else to prevent this? 是否有可能将超时添加为参数或其他方法来防止这种情况?

I'm using Windows Server 2008R2 and .NET 4 我正在使用Windows Server 2008R2和.NET 4

PowerShell won't terminate a script early because of a timeout - so that isn't the problem. PowerShell不会因为超时而提前终止脚本-但这不是问题。 The most likely causes are that something in your script is raising an exception or possibly the Task Scheduler is configured to kill a task that runs too long. 最可能的原因是脚本中的某些内容引发了异常,或者可能是任务计划程序被配置为杀死运行时间过长的任务。 Either way, you can probably find the information to diagnose that in the event log or the task scheduler log. 无论哪种方式,您都可以在事件日志或任务计划程序日志中找到诊断信息。

An easy place to check is the task properties you have created. 一个简单的地方就是您创建的任务属性。 On the Settings tab there is an option to "stop the task if it runs longer than" - you might have that enabled and set to 1 hour. 在“设置”选项卡上,有一个选项“如果任务运行时间超过了则停止任务”-您可能已启用该任务并将其设置为1小时。

任务计划程序设置

There's another gotcha: Go into the Trigger and you'll find another place Windows can kill your Task. 还有另一个陷阱:进入触发器,您将找到Windows可以杀死您的Task的另一个位置。

触发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM