Hi
Error - Error - An object reference is required for non static field , method or property Process.Kill
I have below code and it is giving me above error on process.kill
C#
public static void RunVideo(string videolink)
{
var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink);
Process.Start(_process);
Process.Kill();
}Thanks

Amit MohantyRank #112 · 20K reputationPosted Dec 2, 2022, 4:52 AM EST
Try this
var process = Process.Start(_process); process.Kill();Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 4:59 AM EST
Hi AMit
If i do like this Video does not run. It opens multiple Browser windows
I want it should run & browser gets close.
for (int i = 0; i < 10; i++)
{
//https://www.youtube.com/watch?v=M-FfmU2ieOI
RunVideo("youtube.com/watch?v=M-FfmU2ieOI?autoplay=1");
}
public static void RunVideo(string videolink) { var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink); Process.Start(_process); Process.Kill(); }Vishal YelveRank #178 · 13.6K reputationPosted Dec 2, 2022, 6:32 AM EST
Try this
Process process = new Process(); var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink); process.StartInfo = _process; process.Kill();Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 6:45 AM EST
Hi Vishal
It is giving message No process is associated with this object.
Process process = new Process(); var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink); process.StartInfo = _process; process.Kill();Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Dec 2, 2022, 7:04 AM EST
Hi Ramco,
Try this, I have tested
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(); }Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 7:10 AM EST
Hi Vishal
On process.kill it is giving error - Cannot process request because the process has exited.
Video also run only 1 time
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 7:16 AM EST
Hi Vishal
Kindly check at your end it is not going at this point. AT process.start Video starts but it is not going at below point .
process.WaitForExit(10000);
// milliseconds process.Kill();
Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Dec 2, 2022, 8:47 AM EST
Hi Ramco,
Try this.
public static void RunVideo(string videolink) { var 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(); }static void Main(string[] args) { Console.WriteLine("Process Start!"); for (int i = 0; i < 4; i++) { RunVideo("youtube.com/watch?v=MYojqnJ34g4?autoplay=1"); } Process[] processNames = Process.GetProcessesByName("msedge"); foreach (var item in processNames) { item.Kill(); } }Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 9:07 AM EST
Hi Visahl
On item.kill it is giving access denied.
Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Dec 2, 2022, 9:19 AM EST
Please share you complete code.. coz its working properly at my end
Ramco RamcoRank #462 · 5.4K reputationPosted Dec 2, 2022, 9:24 AM EST
Hi Vishal
Loop is not working . I am reading 4-5 videos from Database . I want it should repeat 1 after other. It stops after first video.
It should kill that process & start new process . I think then it will work.
for (int i = 0; i < 4; i++) { RunVideo("youtube.com/watch?v=M-FfmU2ieOI?autoplay=1"); } Process[] processNames = Process.GetProcessesByName("msedge"); foreach (var item in processNames) { item.Kill(); } public static void RunVideo(string videolink) { var 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(); }