Process proc=null;//declaration at top of windows form code
proc = Process.Start(imagefilename);
if (proc != null) proc.Kill();
but proc is always null.
if I use proc = new Process(); proc.StartInfo.FileName=imagefilename; proc.Start(); proc.Kill()//after image showing. gives no process associate error. Help! I am using VS 2012 Express because I have to use and create Windows Forms and newer version don't support that well or at all.
Naimish MakwanaPosted Apr 1, 2023, 4:58 AM
Try below,
Thanks
Jon JacobsPosted Mar 31, 2023, 9:49 PM
Whenever I use proc.Kill(); I get: "No process is associated with this object."
I think I get what is happening. As soon as the Windows Photo Viewer is launched by proc.Start, the process immediately exits. So what I really need is a way to find the Windows Photo Viewer instance and kill it. In a run of my program, I will have launched dozens of images, so I need to be able to kill the current one before launching the next one.
Jon JacobsPosted Mar 31, 2023, 9:39 PM
How do I kill a process by its handle? the Kill method doesn't take parameters.
Jon JacobsPosted Mar 31, 2023, 9:33 PM
Thank you.
Process proc = Process.Start(startInfo); ALWAYS returns null for me.
So I will experiment with:
ProcessStartInfo startinfo = new ProcessStartInfo(imagefilename);
proc = new Process();
proc.StartInfo = startinfo;
proc.Start();
handle = proc.Handle;
Tuhin PaulPosted Mar 31, 2023, 5:33 PM
we use ProcessStartInfo to create a new process and specify the file name of the image to be displayed. Then we start the process using Process.Start() and store the returned Process object in a variable imageProcess.
Tuhin PaulPosted Mar 31, 2023, 5:31 PM
To kill a process that displays an image file, you first need to start the process using
Process.Start()and then obtain the process handle to kill it.