[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

C# : Not showing all processes in list

Posted on 2010-03-30
6
Medium Priority
?
352 Views
Last Modified: 2013-12-17
I've created a small app to show top 10 processes by working set size.
My problem is that it does not show the correct top 10 list.
The attached code is what I wrote. When I compare my list with task manager process list, the result are not the same.
In the task manager I see processes not listed in my list. for example the 'dwm' process is missing from my list.
but when I use :
Process[] processList = Process.GetProcessesByName("dwm");
the process is shown in the list

string[] TopTenName = new string[10];
        long[] TopTenVal = new long[10];

        private void Form1_Load(object sender, EventArgs e)
        {
            Process[] processList = Process.GetProcesses();

            string _Break;
            int _TopTenCount;
            foreach (Process p in processList)
            {
                _Break = "No";
                _TopTenCount = 0;
                while (_Break == "No")
                {
                    if (TopTenVal[_TopTenCount] < (p.WorkingSet64 / 1024))
                    {
                        TopTenName[_TopTenCount] = p.ProcessName;
                        TopTenVal[_TopTenCount] = p.WorkingSet64 / 1024;
                        _Break = "Yes";
                    }
                    _TopTenCount++;
                    if (_TopTenCount == 10) _Break = "Yes";
                }
            }

            ListViewItem lvName;
            ListViewItem lvVal;

            listView1.Items.Clear();
            listView1.BeginUpdate();

            for (int n = 0; n < 10; n++)
            {
                lvName = new ListViewItem();
                lvVal = new ListViewItem();

                lvName.Text = TopTenName[n];
                lvVal.Text = TopTenVal[n].ToString("0,0");

                lvName.SubItems.Add(lvVal.Text);
                listView1.Items.Add(lvName);
            }

            listView1.EndUpdate();
            listView1.View = View.Details;
            listView1.Focus();
        }

Open in new window

0
Comment
Question by:OrenRozen
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 29124890
Use the overloaded version of GetProcesses as below. I can't find the question I saw this on before, but there is a reason you have to do it this way and I cannot remember what it was :\
Process[] processList = Process.GetProcesses(Environment.MachineName);

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 29125139
I believe this also works:
Process[] processList = Process.GetProcesses(".");

Open in new window

0
 
LVL 3

Author Comment

by:OrenRozen
ID: 29126619
both suggestions didn't solve the issue.
another thing I didn't mention is that I'm running in 64 bit environment. don't no why it should matter, but...

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 29127780
Maybe I'm confusing that with something else then :\

Are you compiling the code as x86 or x64?
0
 
LVL 3

Author Comment

by:OrenRozen
ID: 29128956
same results for x86 and x64. default is Any CPU.

what puzzles me is why the code (when using GetProcesses()) is not showing the 'dwm' process in the list while when using GetProcessesByName("dwm")
is (and the only) showing in the list.
BTW, the 'dwm' process is the third in memory size.
0
 
LVL 3

Accepted Solution

by:
OrenRozen earned 0 total points
ID: 29208526
no more ideas?
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question