View Single Post
Old June 10th, 2009   #35 (permalink)
S.T.A.R.S.
 
S.T.A.R.S.'s Avatar
 
Join Date: Jan 2006
Location: Planet Earth...
Posts: 593
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...
S.T.A.R.S. is offline   Reply With Quote