 |
|
 |
| |
Developer on focus
Anton Zamov is a dipl. engineer with more than 6 years of active professional
experience and many awards ...
read more>>
|
|
 |
 |
 |
|
 |
|
 |
| |
|
How to get information for the system processes?
|
In fact this methos provide the same information for the system processes as the well known Windows Task Manager.
public DataSet getProcesses()
{
/*
This method is created by Anton Zamov.
web site: http://zamov.online.fr
Feel free to use and redistribute this method
in condition that you keep this message intact.
*/
Process[] procs;
TimeSpan cputime;
procs = Process.GetProcesses();
DataSet myDataSet = new DataSet("myDataSet");
DataTable tProc = new DataTable("nc");
// name, pid, time, mem, peakmem, handles, threads;
DataColumn pName = new DataColumn("name", typeof(string));
DataColumn pPid = new DataColumn("pid", typeof(string));
DataColumn pTime = new DataColumn("time", typeof(string));
DataColumn pMem = new DataColumn("mem", typeof(string));
DataColumn pPeakmem = new DataColumn("peakmem", typeof(string));
DataColumn pHandles = new DataColumn("handles", typeof(string));
DataColumn pThreads = new DataColumn("threads", typeof(string));
tProc.Columns.Add(pName);
tProc.Columns.Add(pPid);
tProc.Columns.Add(pTime);
tProc.Columns.Add(pMem);
tProc.Columns.Add(pPeakmem);
tProc.Columns.Add(pHandles);
tProc.Columns.Add(pThreads);
myDataSet.Tables.Add(tProc);
string name, pid, time, mem, peakmem, handles, threads;
DataRow newRow2;
foreach(Process proc in procs)
{
proc.Refresh();
cputime = proc.TotalProcessorTime;
name = proc.ProcessName;
pid = proc.Id.ToString();
time = String.Format(
"{0}:{1}:{2}",
((cputime.TotalHours-1<0?0:cputime.TotalHours-1)).ToString("##0"),
cputime.Minutes.ToString("00"),
cputime.Seconds.ToString("00")
);
mem = (proc.WorkingSet/1024).ToString()+"k";
peakmem = (proc.PeakWorkingSet/1024).ToString()+"k";
handles = proc.HandleCount.ToString();
threads = proc.Threads.Count.ToString();
newRow2 = tProc.NewRow();
newRow2["name"]= name;
newRow2["pid"]= pid;
newRow2["time"]= time;
newRow2["mem"]= mem;
newRow2["peakmem"]= peakmem;
newRow2["handles"]= handles;
newRow2["threads"]= threads;
tProc.Rows.Add(newRow2);
proc.Close();
}
procs = null;
return myDataSet;
}
|
About the author of this programming example or tutorial:
Anton Zamov is a software engineer with more than6 years
of active experience in web and software development and design.
Anton Zamov has extensive experience and broad knowledgebase
in C# and JAVA programming and has created a lot of
running e-commerce systems, portals and content management
systems using PHP and other web development technologies.
For more information about Anton Zamov, you may visit the personal web site of
Anton Zamov.
|
|
|
 |
 |
 |
|
|