[ Team LiB ] Previous Section Next Section

Processmarshal by reference, disposable

System.Diagnostics (system.dll)class

This class represents a system process. Use it to start, stop, and interact with a process. To launch a new process, create an instance of ProcessStartInfo, set its properties, and pass it to the single-argument form of the static Start( ) method. This offers a great deal of control over process creation. To launch a process without customizing its StartInfo, simply call the one-string or two-string argument form of the static Start( ) method. The first string argument is the name of the program, batch file, or document to start, and the optional second argument contains any command-line arguments. You can also explicitly create a new instance of Process, set its StartInfo property, and call the Start( ) method to start the process.

GetCurrentProcess( ) creates a Process instance that represents the current process. Enumerate all running processes on the system by using GetProcesses( ). Use GetProcessesByName( ) to get all processes for a given program. GetProcessById( ) retrieves a Process given its process ID.

Use CloseMainWindow( ) to shut down a process that has a user interface. You can terminate a process with Kill( ), but this forces an abnormal termination, which may result in data corruption. If you would like to raise an event when the process finishes executing, use Exited (EnableRaisingEvents must be set to true).

Most of the properties allow you to access general information about the running process. However, this information is populated at the time you associate a Process object with a running process. You can call Refresh( ) each time you need to update this information. Modules allows you to inspect the code modules the process has loaded into memory, and MainModule returns the module that started the process. StandardInput, StandardOutput, and StandardError allow access to the default I/O streams (see the ProcessStartInfo.Redirect* methods). Threads returns the threads in use by the process, and WorkingSet returns the physical memory usage of the process.

public class Process : System.ComponentModel.Component {
// Public Constructors
   public Process( );
// Public Instance Properties
   public int BasePriority{get; }
   public bool EnableRaisingEvents{set; get; }
   public int ExitCode{get; }
   public DateTime ExitTime{get; }
   public IntPtr Handle{get; }
   public int HandleCount{get; }
   public bool HasExited{get; }
   public int Id{get; }
   public string MachineName{get; }
   public ProcessModule MainModule{get; }
   public IntPtr MainWindowHandle{get; }
   public string MainWindowTitle{get; }
   public IntPtr MaxWorkingSet{set; get; }
   public IntPtr MinWorkingSet{set; get; }
   public ProcessModuleCollection Modules{get; }
   public int NonpagedSystemMemorySize{get; }
   public int PagedMemorySize{get; }
   public int PagedSystemMemorySize{get; }
   public int PeakPagedMemorySize{get; }
   public int PeakVirtualMemorySize{get; }
   public int PeakWorkingSet{get; }
   public bool PriorityBoostEnabled{set; get; }
   public ProcessPriorityClass PriorityClass{set; get; }
   public int PrivateMemorySize{get; }
   public TimeSpan PrivilegedProcessorTime{get; }
   public string ProcessName{get; }
   public IntPtr ProcessorAffinity{set; get; }
   public bool Responding{get; }
   public StreamReader StandardError{get; }
   public StreamWriter StandardInput{get; }
   public StreamReader StandardOutput{get; }
   public ProcessStartInfo StartInfo{set; get; }
   public DateTime StartTime{get; }
   public ISynchronizeInvoke SynchronizingObject{set; get; }
   public ProcessThreadCollection Threads{get; }
   public TimeSpan TotalProcessorTime{get; }
   public TimeSpan UserProcessorTime{get; }
   public int VirtualMemorySize{get; }
   public int WorkingSet{get; }
// Public Static Methods
   public static void EnterDebugMode( );
   public static Process GetCurrentProcess( );
   public static Process GetProcessById(int processId);
   public static Process GetProcessById(int processId, string machineName);
   public static Process[ ] GetProcesses( );
   public static Process[ ] GetProcesses(string machineName);
   public static Process[ ] GetProcessesByName(string processName);
   public static Process[ ] GetProcessesByName(string processName, string machineName);
   public static void LeaveDebugMode( );
   public static Process Start(ProcessStartInfo startInfo);
   public static Process Start(string fileName);
   public static Process Start(string fileName, string arguments);
// Public Instance Methods
   public void Close( );
   public bool CloseMainWindow( );
   public void Kill( );
   public void Refresh( );
   public bool Start( );
   public override string ToString( );    
// overrides System.ComponentModel.Component
   public bool WaitForExit(int milliseconds);
   public void WaitForExit( );
   public bool WaitForInputIdle( );
   public bool WaitForInputIdle(int milliseconds);
// Protected Instance Methods
   protected override void Dispose(bool disposing);  
// overrides System.ComponentModel.Component
   protected void OnExited( );
// Events
   public event EventHandler Exited;
}

Hierarchy

System.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponent, System.IDisposable) Process

    [ Team LiB ] Previous Section Next Section