473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Pro cess List");

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

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

//here we get an array of threads from the process
Process[] ObjModulesList =
Process.GetProc essesByName(pro cList[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
{
ProcessModuleCo llection ObjModules = ObjModulesList[0].Modules;
foreach (ProcessModule objModule in ObjModules)
{
treeProcessTree .Nodes[0].Nodes[i].Nodes.Add(objM odule.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("Err or 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 (treeProcessTre e.Nodes[0].Nodes[i].Text == "Idle")
{
treeProcessTree .Nodes[0].Nodes[i].ForeColor = Color.Blue;
treeProcessTree .Nodes[0].Nodes[i].Nodes[0].Remove();
}
if (treeProcessTre e.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 1426

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

Similar topics

1
2601
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
3110
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 inherits popen2.Popen3. The problem is that popen2.Popen3 does not define a __del__ method to handle proper closing of the pipes or destruction of the process. So I created one in my class:
3
2176
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 line instructions in process.Process? I tried a list with the same result. If you're wondering why I'm switching, it's because I'm working with a poorly behaved 3rd party program that causes a severe memory leak, and I
2
5357
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 (Standard Exe) that calls and controls other modules (ActiveX-Exe). We decided for ActiveX-Exe because they run in different processes. That means if one module shuts down, the others are still alive. Second reasons
10
14422
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 user to gain the required rights for execution (the external process needs to create a mailbox in Exchange, so it needs to be run as an Exchange Full Administrator-powered user). For the moment, I have tries using the Start() static method of the...
1
2107
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. Instead, I just have a warning for security reasons and 2 buttons (Attach | Don't attach). Let me explain a bit... I have several web applications running on different servers. All servers are XP 2003 Servers with IIS 6. My applications runs in...
3
5213
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 process, and it would only run as long as the real processes ran. I think this is a better way to stop gnuchess, as you are 100% sure, that it'll stop. Can you do this with popen?
3
2197
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 disappears into never-never land. LONG VERSION: I am working on a site that can kick off large-scale simulations. It will write the output to an html file and a link will be emailed to the user. Also, the site will continue to display...
3
9180
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 arguments that would tell on which interpreter to run the string...? Marcin
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.