Process


The Process component provides access to the processes running on the computer. You can use this object to start, stop, and monitor processes. You can use the object to get information about a running process (such as its threads, the modules it has loaded, and the amount of memory it is using).

The following code shows how a program can start an excutable program. It creates a new Process object and sets values in its StartInfo property to define the application to run. This example sets the executable file name to the string contained in the txtFileName text box and sets the component’s Verb to Open (opening an executable file makes it run). The program then calls the object’s Start method.

  ' Start the process. Private Sub btnRun_Click(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles btnRun.Click     Dim new_process As New Process     new_process.StartInfo.FileName = txtFileName.Text     new_process.StartInfo.Verb = "Open"     new_process.Start() End Sub 

The Process object’s StartInfo property contains several values that tell the object how to start the new process. These values indicate whether the new process should be created without a window; what environment variables it should use; whether the new process’s standard input, output, and error streams should be redirected; and the new process’s working directory.

The Process object itself provides only a few properties at design time. Other than the StartInfo property, the most useful of these is EnableRaisingEvents. If this property is True, then the component monitors the new process and raises an Exited event when the process ends.

At runtime, the Process object also provides read-only StandardInput, StandardOutput, and StandardError properties that the program can use to interact with the new process. It also provides methods for reading and writing with these streams, and properties for monitoring the process. For example, it lets you learn about the process’s working set size, paged memory size, total processor time, and so forth.

This is a fairly advanced and specialized topic, so it is not covered in greater detail here. For more information, see the Process component’s web page at msdn.microsoft.com/library/en-us/cpref/html/ frlrfsystemdiagnosticsprocessclasstopic.asp.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net