How to kill process in visual studio 2008 c#? I tried the below code
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace GR
{
public partial class Form1 : Form
{
public Login loginform;
public EntryForm entryform;
public Form1()
{
//userName = "";
InitializeComponent();
//CheckForInternetConnection();
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.StartsWith("Bin_"))
{
clsProcess.Kill();
}
}
loginform=new Login();
entryform = new EntryForm();
Controls.Add(loginform);
Controls.Add(entryform);
loginform.Show();
entryform.Hide();
loginform.entryForm = entryform;
entryform.loginForm = loginform;
}
}
}
I am getting this error
'System.Diagnostics.Process' does not contain a definition for 'GetProcesses'.
Any suggestion ?
The ompact Framework doesn't support it, which is why you get the error. The fallback is to use the Toolhelp APIs, like the SDF does. Take a look at the ProcessEntry
class in the SDF. Specifically the GetProcesses()
method and the subsequent Kill()
method.