c# help (process list)

Posts 1–9 of 9 · Page 1 of 1
c# help (process list)
Can somebody help me with a Process List in c# winforms....like Have a listview that shows all the processes thats all i need.
One sec, I will write it.

Going to properly convert my tut without errors, This is my 64 bit test machine, so give me a little bit to download C# on here.
Just take the output from Process.GetProcesses() and either bind it to your listview or manually iterate over it with a foreach loop to do some processing etc while you're adding them. something like:

Code:
using System.Diagnostics;
...

Process[] processList = Process.GetProcesses();
foreach(Process p in processList)
{
     ListViewItem lvi  = new ListViewItem();
     lvi.Text = p.ProcessName;
     lvi.Tag = p.Id;
     processListView.Items.Add(lvi);
}
Code:
foreach(Process p in processList)
Do you really write it like that in C# o_O?
Quote Originally Posted by why06 View Post
Code:
foreach(Process p in processList)
Do you really write it like that in C# o_O?
i know rite.. Looks like vb D=
Quote Originally Posted by why06 View Post
Code:
foreach(Process p in processList)
Do you really write it like that in C# o_O?
Eitherway - this also works:
Code:
for(int i = 0 ; i < processList.Count; i++)
{
   processList[i].Id; //etc etc
}
But if you have no need to know the index the foreach iterator is simpler and more elegant
Quote Originally Posted by B1ackAnge1 View Post
Eitherway - this also works:
But if you have no need to know the index the foreach iterator is simpler and more elegant
I sorta disagree, but thx 4 info.
Lol sry Next BA's got this.
Lol Why. yeah it's no plain old C++ but you get used to it. But that's why there's multiple ways to do it so you can pick what you like Compared to Template classes or STL type iterators etc in C++, C#'s way of dealing with this stuff like generics actually is I think quite a bit nicer, though I miss my multiple inheritance at times. (not supported in C#, though you can still implement multiple interfaces in one class so it 'sorta' lets you do it).

Of course the downside of using a foreach loop is that you can't change your collection you're iterating over (delete/add items, but you can still modify the individual objects) while inside it, so it has it's place , but usually only for 'readonly/forwardonly' operations.

Just for fun I should do write a tut that's 'C++ vs C#' on some common concepts etc.
damn it, I was writing up a conversation of my tut

NextGen1 tut = fails

rage quits!
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us