Download - 6.C#
Introduction Process
Topics
Basic of process Overview of all Properties Overview of all Methods Overview of all Events Process.Start() Method
Open Files using process Example Open Web page or Lunch URL using process Example Lunch .exe using process Example
Define Process
A process is an instance or execution of a program.
Every process contains a program code and the existing activity
The Process class(System.Diagnostics.Process) retrieves various information Execute single programs
Properties of Process
Public BasePriority Gets the base priority of the associated process.
Protected CanRaiseEvents Gets a value indicating whether the component can raise an event. (Inherited
from Component.) Public Container
Gets the contains the Component. (Inherited from Component.) The components in a container are tracked in a first-in, first-out list, which also
defines the order of the components within the container. The last component added is the last component in the list.
Protected DesignMode Gets a value that indicates whether the Component is currently in design
mode. Public EnableRaisingEvents
Gets or sets whether the Exited event should be raised when the process terminates.
Protected Events Gets the list of event handlers that are attached to this Component
Public Handle Gets the native handle of the associated process.
Public HandleCount Gets the number of handles opened by the
process.Public HasExited
Gets a value indicating whether the associated process has been terminated.
Public Id Gets the unique identifier for the associated
process.
Public MachineName Gets the name of the computer the associated process is running on.
Public MainModule Gets the main module for the associated process. A process module represents a.dll or .exe file that is loaded into a particular process.
The MainModule property lets you view information about the executable used to start the process, including the module name, file name, and module memory details.
Public MainWindowHandle Gets the window handle of the main window of the associated process.
A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, theMainWindowHandle value is zero.
Public MainWindowTitle Gets the caption of the main window of the process.
Public MaxWorkingSet Gets or sets the maximum allowable working set size for the associated process.
The working set of a process is the set of memory pages currently visible to the process in physical RAM memory.
Public MinWorkingSet Gets or sets the minimum allowable working set size for the associated process.
Public Modules Gets the modules that have been loaded by the associated
process. A process module represents a.dll or .exe file that is loaded into a
particular process. A ProcessModule instance lets you view information about a module,
including the module name, file name, and module memory details.Public NonpagedSystemMemorySize64
Gets the amount of nonpaged system memory allocated for the associated process. The nonpaged pool consists of virtual memory addresses that are
guaranteed to reside in physical memory Public PagedMemorySize64 Gets the amount of paged memory allocated for the associated
process. The paged pool consists of virtual memory that can be paged in and out of
the system.
Public PagedSystemMemorySize64 Gets the amount of pageable system memory
allocated for the associated process.Public PeakPagedMemorySize64
Gets the maximum amount of memory in the virtual memory paging file used by the associated process.
Public PeakVirtualMemorySize64 Gets the maximum amount of virtual memory used by
the associated process.
Public PeakWorkingSet64 Gets the maximum amount of physical memory used by the associated process. Gets the peak working set size for the associated process. The working set of a process is the set of memory pages currently visible to the process in physical RAM
memory.
Public PriorityBoostEnabled Gets or sets a value indicating whether the associated process priority should temporarily be boosted by
the operating system when the main window has the focus. Public PriorityClass
Gets or sets the overall priority category for the associated process. //4 Idle //8 Normal //13 High //24 RealTime
Public PrivateMemorySize64 Gets the amount of private memory allocated for the associated process. The number of bytes allocated by the associated process that cannot be shared with other processes.
Public PrivilegedProcessorTime Gets the privileged processor time for this process.
Public ProcessName Gets the name of the process.
Public ProcessorAffinity Gets or sets the processors on which the threads in this process can
be scheduled to run. Public Responding
Gets a value indicating whether the user interface of the process is responding.
Public SessionId Gets the Terminal Services session identifier for the associated
process. The SessionId property identifies the session in which the application is
currently running. Public Site
Gets or sets the ISite of the Component. (Inherited from Component.)
Public StartInfo Gets or sets the properties to pass to the Start
method of the Process.Public StartTime
Gets the time that the associated process was started.Public SynchronizingObject
Gets or sets the object used to marshal the event handler calls that are issued as a result of a process exit event.
Show ExamplePublic Threads
Gets the set of threads that are running in the associated process.
Public TotalProcessorTime Gets the total processor time for this process.
Public UserProcessorTime Gets the user processor time for this process.
Public VirtualMemorySize64 Gets the amount of the virtual memory allocated for
the associated process.Public WorkingSet64
Gets the amount of physical memory allocated for the associated process.
Sample Example
Get All Properties of Process
Process Methods
Public method BeginErrorReadLine Begins asynchronous read operations on the redirected
StandardError stream of the application.Public method BeginOutputReadLine
Begins asynchronous read operations on the redirected StandardOutput stream of the application.
Public method CancelErrorRead Cancels the asynchronous read operation on the redirected
StandardError stream of an application.Public method CancelOutputRead
Cancels the asynchronous read operation on the redirected StandardOutput stream of an application.
Public method Close Frees all the resources that are associated with this
component.
Public method CloseMainWindow Closes a process that has a user interface by sending a close message to
its main window. Public method CreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Dispose() Releases all resources used by the Component. (Inherited from
Component.) Protected method Dispose(Boolean)
Infrastructure. Release all resources used by this process. (Overrides Component.Dispose(Boolean).)
Public method Static member EnterDebugMode Puts a Process component in state to interact with operating system
processes that run in a special mode by enabling the native property SeDebugPrivilege on the current thread.
Public method Equals(Object) Determines whether the specified object is equal to the current object.
(Inherited from Object.) Protected method Finalize
Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Public method Static member GetCurrentProcess Gets a new Process component and associates it with the currently active
process. Public method GetHashCode
Serves as the default hash function. (Inherited from Object.) Public method GetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method Static member GetProcessById(Int32) Returns a new Process component, given the identifier of a process on the
local computer.
Public method Static member GetProcessById(Int32, String) Returns a new Process component, given a process identifier and the name of a computer on the network. Show Example
Public method Static member GetProcesses() Creates a new Process component for each process resource on the local computer.
Show Example
Public method Static member GetProcesses(String) Creates a new Process component for each process resource on the specified
computer. Public method Static member GetProcessesByName(String) Creates
an array of new Process components and associates them with all the process resources on the local computer that share the specified process name.
Public method Static member GetProcessesByName(String, String)Creates an array of new Process components and associates them with all the process resources on a remote computer that share the specified process name.
Protected method GetService Returns an object that represents a service provided by the
Component or by its Container. (Inherited from Component.)Public method GetType
Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method Kill Immediately stops the associated process.
Public method Static member LeaveDebugMode Takes a Process component out of the state that lets it
interact with operating system processes that run in a special mode.
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method OnExited Raises the Exited event.
Public method Refresh Discards any information about the associated process that has
been cached inside the process component.Public method Start()
Starts (or reuses) the process resource that is specified by the StartInfo property of this Process component and associates it with the component.
Public method Static member Start(ProcessStartInfo) Starts the process resource that is specified by the parameter containing process start information (for
example, the file name of the process to start) and associates the resource with a new Process component.
Public method Static member Start(String) Starts a process resource by specifying the name of a document or application file and associates the resource
with a new Process component.
Public method Static member Start(String, String) Starts a process resource by specifying the name of an application and a set of command-line
arguments, and associates the resource with a new Process component.
Public method Static member Start(String, String, SecureString, String) Starts a process resource by specifying the name of an application, a user name, a password, and a domain and associates the resource with a new Process component.
Public method Static member Start(String, String, String, SecureString, String)Starts a process resource by specifying the name of an application, a set of command-line arguments, a user name, a password, and a domain and associates the resource with a new Process component.
Public method ToString Formats the process's name as a string, combined with the parent component type, if
applicable. (Overrides Component.ToString().)
Public method WaitForExit() Instructs the Process component to wait indefinitely for the
associated process to exit.Public method WaitForExit(Int32)
Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.
Public method WaitForInputIdle() Causes the Process component to wait indefinitely for the
associated process to enter an idle state. This overload applies only to processes with a user interface and, therefore, a message loop.
Public method WaitForInputIdle(Int32) Causes the Process component to wait the specified number
of milliseconds for the associated process to enter an idle state. This overload applies only to processes with a user interface and, therefore, a message loop.
Sample Methods Example
Process Events
Public event Disposed Occurs when the component is disposed by a call to
the Dispose method. (Inherited from Component.)Public event ErrorDataReceived
Occurs when an application writes to its redirected StandardError stream.
Public event Exited Occurs when a process exits.
Show Example
Public event OutputDataReceivedOccurs when an application writes to its
redirected StandardOutput stream.