473,241 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Process List / Module List problem..


I'm new to C#.

I am using the following C# method to populate a TreeView control. If
you call this method once during the life of form then it works
perfectly. If you call the method a second time (without closing and
reloading the app) then the process list populates the TreeView
control with varying degrees of success. Sometimes the process name
shows up (or not), threads that can load modules are red while others
are not and threads that even show during the debug process as being
added to the treeview appear to succeed (and the process name appears
in the treeview control correctly) but the module list never shows up.

I have stepped through the process a couple dozen times and from what
I can gather.. what is appearing in the debug/watch Window is not
making it back to the control.

The formatting and style of the method has been rewritten a dozen
different times today in an attempt to understand where I am going
wrong so it is no longer as elegant as it should be. Once I
understand WHY this is wrong.. I can work on making it look pretty.

I should also note that I know there are other ways to do this. I
would like to know why this particular way behaves in this fashion.

I'm using VS2008 Pro on Vista.
//clear the tree
treeProcessTree.Nodes.Clear();
//add the root
treeProcessTree.Nodes.Add("Process List");

//get a list of processes
Process[] procList = Process.GetProcesses();

//for every process.
for (int i = 0; i < procList.Length; i++)
{
//append the process name to the root
treeProcessTree.Nodes[0].Nodes.Add(procList[i].ProcessName.ToString());

//here we get an array of threads from the process
Process[] ObjModulesList =
Process.GetProcessesByName(procList[i].ProcessName);

//below we try to get a list of resources used by each thread
//then we iterate through each of the resources and append the
filename as a child
//to the the process name node
try
{
ProcessModuleCollection ObjModules = ObjModulesList[0].Modules;
foreach (ProcessModule objModule in ObjModules)
{
treeProcessTree.Nodes[0].Nodes[i].Nodes.Add(objModule.FileName.ToString());
}
}
//some threads return a Win32Exception so we deal with it here
//first we append the error message to the tree then change the
process name and its children to RED
//this way you can tell which modules could not be loaded
catch
{
treeProcessTree.Nodes[0].Nodes[i].Nodes.Add("Error retrieving module
list");
treeProcessTree.Nodes[0].Nodes[i].ForeColor = Color.Red;
treeProcessTree.Nodes[0].Nodes[i].Nodes[0].ForeColor = Color.Red;
}

//obviously some threads are not really threads
if (treeProcessTree.Nodes[0].Nodes[i].Text == "Idle")
{
treeProcessTree.Nodes[0].Nodes[i].ForeColor = Color.Blue;
treeProcessTree.Nodes[0].Nodes[i].Nodes[0].Remove();
}
if (treeProcessTree.Nodes[0].Nodes[i].Text == "System")
{
treeProcessTree.Nodes[0].Nodes[i].ForeColor = Color.
treeProcessTree.Nodes[0].Nodes[i].Nodes[0].Remove();
}

}

treeProcessTree.Sort();
treeProcessTree.Nodes[0].Expand();
procList = null;

Jun 27 '08 #1
0 1407

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
1
by: | last post by:
This could possibly be a bug, but I don't understand it fully so I'm posting here first. Searching the list told me other people are having this problem too. I have created a class which...
3
by: Earl Eiland | last post by:
The command string consists of "filename.exe instruction1 instruction2 ...." It works in subprocess, but in process, returns the error "can't find the file instruction1". How do I pass command...
2
by: Berata | last post by:
Hello all, in VB6 we were able to create ActiveX-DLL's (In Process Components) and ActiveX-Exe's (Out of Process Components). We habe build up an application that exists of an main module...
10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
1
by: Martin Simard | last post by:
Hi all, In VS 2003, when I attach to a remote process for debugging, I can see the list of modules loaded by the process before attaching to it. This list is not there anymore in VS 2005....
3
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module, but in java, you could make a process a daemon...
3
by: Pappy | last post by:
SHORT VERSION: Python File B changes sys.stdout to a file so all 'prints' are written to the file. Python file A launches python file B with os.popen("./B 2>&^1 >dev/null &"). Python B's output...
3
by: Marcin Kalicinski | last post by:
How do I use multiple Python interpreters within the same process? I know there's a function Py_NewInterpreter. However, how do I use functions like Py_RunString etc. with it? They don't take any...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.