Forum guidelines
AuthorQuestion
Managing Processes in c#
Posted on: 10 Sep 2012
Hi, First of all sorry my bad English, is not my mother tongue...

How can I know the numbers of I/O bytes of all running processes, like task manager of windows. If somebody has the source code of that o knows where I can get it please help me.

I hope somebody can help me

sandy@cug.co.cu

Thanks a lot
Sandy

AuthorReply
Re: Managing Processes in c#
Posted on: 10 Sep 2012  
Try this:

using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
       Console.Clear();
       long total = 0;
       foreach(Process proc in Process.GetProcesses())
       {
          long mem = proc.WorkingSet64/1024;
          total += mem;
          Console.WriteLine("{0, -25} {1, 9:N0} K", proc.ProcessName, mem);
       }
    
       Console.WriteLine("{0, 37}", "-----------");
       Console.WriteLine("{0, 35:N0} K", total);         
       Console.ReadKey();
    }
}

Re: Managing Processes in c#
Posted on: 14 Sep 2012  
Hi,

        Thanks for your help, but the code you sent me shows the used memory per process what I need is Reading Bytes I/O per process like task manager

Thanks again.
Sandy

Re: Managing Processes in c#
Posted on: 14 Sep 2012  
Sorry, I misread the question :(

To get the I/O Read bytes, you'll need to use WMI as the .NET Process class doesn't expose that particular statistic:

using System;
using System.Management;

class Test
{
    static void Main()
    {
      Console.Clear();
      var searcher = new ManagementObjectSearcher("SELECT * FROM  Win32_Process");
      ulong total = 0;     

      foreach (ManagementObject proc in searcher.Get())
      {
         string name = proc["Name"].ToString().Replace(".exe", "");
         ulong bytes = (ulong)proc["ReadTransferCount"];
         total += bytes;
         Console.WriteLine("{0, -25} {1, 13:N0}", name, bytes);    
      }

      Console.WriteLine("{0, 39}", "-------------");
      Console.WriteLine("{0, 39:N0}", total);         
      Console.ReadKey();
    }

}




Employers - Post Free Jobs

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.