views:

56

answers:

1

hi every1 i want to calculate the process time per thread. how do i do it.? suppose my 100 threads are executing the same method work() concurrently, then if i put the following code help me get what i seek

Process thisProc = Process.GetCurrentProcess();
string procName = thisProc.ProcessName;
DateTime started = thisProc.StartTime;

int memory = thisProc.VirtualMemorySize;
int priMemory = thisProc.PrivateMemorySize;
int physMemory = thisProc.WorkingSet;

ProcessPriorityClass priClass = thisProc.PriorityClass;
TimeSpan cpuTime = thisProc.TotalProcessorTime;

Console.WriteLine(" started: {0}", started.ToString());
Console.WriteLine(" CPU time: {0}", cpuTime.ToString());

Console.WriteLine(" Virtual Memory: {0}", memory + " ; Private Memory: " + priMemory + " ; Physical Memory: " + physMemory);
+2  A: 

GetThreadTimes() provides this info. Very hard to use however since it requires a handle to the thread, something the .NET framework doesn't let you do. The simple solution is to start a Stopwatch inside the thread function and Stop() it at its completion.

Hans Passant
okay.thanks a lot dude
phen