Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Stephen Hewison 19-Jun-12 17:16pm    
What scheduling mechanism are you using? SQL Agent? Windows Scheduling? Your own service based scheduler?

1 solution

You can kill a process using the Process.Kill method.

http://msdn.microsoft.com/en-us/library/t71a733d(v=vs.80).aspx[^]

The following is a more detailed example but in essence the code is:

C#
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[^]

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900