Stop (Kill) process in Windows Application

ramco1917
 
on Dec 04, 2022 10:45 PM
288 Views

Hi

I have below code but it does not go at this line when i debug

Unable to kill process

process.WaitForExit(10000); 

 

public static void RunVideo(string videolink)
{
    Process process = new Process();
    var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink);
    //Process.Start(_process);
    process.StartInfo = _process;
    process.Start();
    process.WaitForExit(10000); // milliseconds
    process.Kill();
}

Thanks

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Dec 05, 2022 12:18 AM

Hi ramco1917

ramco1917 says:
public static void RunVideo(string videolink)
{
    Process process = new Process();
    var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink);
    //Process.Start(_process);
    process.StartInfo = _process;
    process.Start();
    process.WaitForExit(10000); // milliseconds
    process.Kill();
 
}

You could try to use HasExited property to determine if the process has exited.

Please replace above code with below code.

public static void RunVideo(string videolink)
{
    Process process = new Process();
    var _process = new ProcessStartInfo(@"C:\Program Files\Google\Chrome\Application\chrome.exe", videolink);
    //Process.Start(_process);
    process.StartInfo = _process;
    process.Start();
    if (!process.WaitForExit(10000))
    {
        if (!process.HasExited)
        {
            process.Kill();
        }
    }
}