Here is the code I used to display all the currently active processes plus ALL the background processes,(the code for ending the selected process is the same like the one from above example):
privatevoid button1_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
Process[] procs=Process.GetProcesses(Environment.MachineName .ToString());
foreach(Process process in procs)
{
try
{
listBox1.Items.Add(process.MainModule.ModuleName);
}
catch(Exception)
{
//No function to execute...
}
}
}
I would like to hear your opinion about this example...
This code perfectly displays all the currently active processes and all the background processes.However I need to catch the exception otherwise the application crashes because of an unhandled exception of type "System.NullReferenceException" which occurrs in my application.Any idea why??
__________________
GOODBYE FOREVER EVERYONE...