Namespace: System.Diagnostics
Process
A Process component provides access to a process that is
running on a computer. A process, in the simplest terms, is a running
application. A thread is the basic unit to which the operating system allocates
processor time. A thread can execute any part of the code of the process,
including parts currently being executed by another thread.
The Process component is a useful tool for starting,
stopping, controlling, and monitoring applications. Using the Process
component, you can obtain a list of the processes that are running, or you can
start a new process. A Process component is used to access system processes.
After a Process component has been initialized, it can be used to obtain
information about the running process. Such information includes the set of
threads, the loaded modules (.dll and .exe files), and performance information
such as the amount of memory the process is using.
Process Properties:
Process.GetProcessByID
Process.GetProcessByName
Process.GetProcesses
Performance Counter
It represents a Windows NT performance counter component.
Methods
NextSample Obtains a counter sample, and returns the
raw, or uncalculated, value for it.
NextValue Obtains a counter sample and returns
the calculated value for it.
CounterSampleCalculator.ComputeCounterValue(MyPerformanceCounter.NextSample(),MyPerformanceCounter.NextSample());
CounterCreationData
CounterCreationData is helpful in a scenario where we want to
setup our own counter and PerformanceCounter Categories.
CounterCreationDataCollection CCDC =
new CounterCreationDataCollection();
// Add the counter.
CounterCreationData averageCount64 =
new CounterCreationData();
averageCount64.CounterType =
PerformanceCounterType.AverageCount64;
averageCount64.CounterName =
"AverageCounter64Sample";
CCDC.Add(averageCount64);
// Create the category.
PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
"Demonstrates usage of the
AverageCounter64 performance counter type.",CCDC);
Properties of CounterCreationData
CounterHelp
CounterName
CounterType
PerformanceCounterCategory
Main Methods include Create, Delete, Exists, GetCategories and ReadCategory.
GetCategories gives a list of
categories on a machine.
ReadCategory will read all the
counter and performance object instance data that is associated with this
category.
Some Important Performance Counters
PerformanceCounter pc = new
PerformanceCounter(“ASP.NET”,”Applications Running”);
PerformanceCounter pc = new
PerformanceCounter(“.NET CLR Memory”,”# Bytes in all Heaps”);
Pc.InstanceName = “_Global_”;
PerformanceCounter pc = new
PerformanceCounter(“.NET CLR Exceptions”,”# of Exceps Thrown”);
Pc.InstanceName = “_Global_”;
Starting a Process
ProcessStartInfo info = new
ProcessStartInfo();
Info.FileName = “iexplorer.exe”;
Process.Start(info);
Main ProcessStartInfo Properties
FileName executable
path or system executable name;
Arguments String
specifying multiple arguments with spaces.
UseShellExecute Set to false if requiring Password
from user.
UserName Set
to Enviorment.UserName if required authentication.
Password Set
to SecureString obtained from user if required authentication.
Domain Set to domain that user selects
against which we have to authenticate.
StackFrame
A StackFrame is created and pushed on the call stack for
every function call made during the execution of a thread. The stack frame
always includes MethodBase information, and optionally includes file name, line
number, and column number information.
Constructors
Name
|
Description
|
StackFrame ()
|
Initializes a new StackFrame object.
|
StackFrame (Boolean)
|
Initializes a new StackFrame object,
optionally capturing source information.
|
StackFrame (Int32)
|
Initializes a new StackFrame object that
corresponds to a frame above the current stack frame.
|
StackFrame (Int32, Boolean)
|
Initializes a new StackFrame object that
corresponds to a frame above the current stack frame, optionally capturing
source information.
|
StackFrame (String, Int32)
|
Initializes a new StackFrame object that
only contains the given file name and line number.
|
StackFrame (String, Int32, Int32)
|
Initializes a new StackFrame object that
only contains the given file name, line number, and column number.
|
Important Methods
GetFileColumnNumber
|
Gets the column number in the file that
contains the code that is executing. This information is typically extracted
from the debugging symbols for the executable.
|
GetFileLineNumber
|
Gets the line number in the file that
contains the code that is executing. This information is typically extracted
from the debugging symbols for the executable.
|
GetFileName
|
Gets the file name that contains the code
that is executing. This information is typically extracted from the debugging
symbols for the executable.
|
GetMethod
|
Gets the method in which the frame is
executing.
|
StackTrace
Represents a stack trace, which is an ordered collection of
one or more stack frames. StackTrace might not report as many method calls as
expected, due to code transformations that occur during optimization.
StackTrace st = new
StackTrace(true);
for(int i =0; i< st.FrameCount;
i++ )
{
// Note that high up the call stack, there is only
// one stack frame.
StackFrame sf = st.GetFrame(i);
Console.WriteLine();
Console.WriteLine("High up the call stack, Method: {0}",
sf.GetMethod());
Console.WriteLine("High up the call stack, Line Number: {0}",
sf.GetFileLineNumber());
}
Methods:
GetFrame
|
Gets the specified stack
frame.
|
GetFrames
|
Returns a copy of all stack
frames in the current stack trace.
|
Comments