问题描述
我将某些自动化安排为在特定时间段运行,例如从凌晨3点开始.该自动化程序计划每2小时运行一次.这种自动化运行程序的exe,该程序从数据库中获取记录,并通过邮件将此记录发送给用户.
这种自动化的问题在于,该自动化通常需要60分钟才能执行,但有时需要5、6、10个小时才能执行,因此下一个小时的通知将不会发送.当我运行相同的自动化并具有相同的sp时,为什么仍会发生这种情况?我已经检查了sp是否正常运行.
有人帮我摆脱它吗?或向我建议解决方案,以便如果花费超过2个小时就可以终止该进程并启动下一个实例.
谢谢,
Umesh Tayade
Hi,
I have certain automation that are schedulled to be run at specific time period like it starts in the morning 3 AM. This automation is schedulled to be run after every 2 hour. This automation run the exe of the program that fetches the record from the database and send this records through the mail to users.
The problem with this automation is that this automation generally should take 60 min to execute but sometime it takes 5,6,10 hrs to execute so that the notification for the next hours will not be send. As i m running the same automation and having the same sp still why this happens? I have checked the sp it is running properly.
do anyone help me to get rid of it? or suggest me the solution so that i can kill the process if it is taking more than 2 hrs and start the next instance.
Thanks,
Umesh Tayade
推荐答案
using System.Diagnostics;
Process[] processes = Process.GetProcessesByName(processName, machineName);
foreach(Process process in processes)
{
process.Kill();
process.WaitForExit();
}
http://weblogs.asp.net/stanleygu/archive/2010/03/31/tip-13-kill-a-process-from-local-to-remote.aspx [ ^ ]
尽管杀死进程不是一个好习惯.尤其是在您的过程中.您可以决定某种类型的出口指针. SQL表行或文本文件中的特定内容.如果要停止正在运行的进程,请设置指针,正在运行的进程在检测到指针时会从正在执行的操作中退出.
http://weblogs.asp.net/stanleygu/archive/2010/03/31/tip-13-kill-a-process-from-local-to-remote.aspx[^]
Although killing processes is not a good practice. Especially if it''s your process. You could decide on some type of exit pointer. Perhaps specific content in an SQL table row or a text file. If you want the running process to stop, set the pointer, the running process, when it detects the pointer, exits nicely from what ever it is doing.
这篇关于计划任务时间变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!