[C # Network application programming] 1, the operation of the process

Source: Internet
Author: User

In. NET, the process class provides a variety of ways to manage processes.

First, how to get the process collection:

process[] myprocesses = process.getprocesses (); Get all processes on the local machine

process[] myprocesses = process.getprocesses (string IP); Get all processes on a remote computer

process[] myprocesses = process.getprocessesbyname (string name); Get local machine All processes by name

process[] myprocesses = Process.getprocessesbyname (string name, string IP); Get local machine All processes by name

1. Some properties and methods for a single process (assuming process aprocess=myprocesses[0]):1.1 Aprocess.modules Some information about the process (assuming processmodulecollection Modules = aprocess.modules)

Each process contains this property, but not every process can be retrieved from that property.

The first member of the collection is identical to the Mainmodule property

1.1.1 Mainmodule The main module of the process (assuming processmodule amodule = aprocess.mainmodule)

1.1.1.1 Amodule.filename the full path to the process

1.1.1.2 Amodule.modulename The name of the process module

1.1.1.3 Amodule.fileversioninfo version information for this module (assuming fileversioninfo vinfo = amodule.fileversioninfo)

1.1.1.3.1 fileversioninfo.fileversion Version

1.1.1.3.2 fileversioninfo.filedescription Description

1.1.1.3.3 Fileversioninfo.language Language

1.2 Aprocess.starttime The start time of the process 1.3 aprocess.id the process's id1.4 aprocess.processname the name of the process 1.5 Aprocess.workingset64 The amount of physical memory allocated by the process (in bytes) 1.6 aprocess.hasexited Returns whether a BOOL value hint has been stopped (must be for a process that has already been started, and if the start () method has not been executed for just new, the card will not be able to continue in that step) 1.7 Apocess.waitforinputidle () waits for the new process to complete its initialization and waits for user input.

Second, start and stop process

You first create a process instance, set the appropriate StartInfo property, and then call the instance's start () method, and when you do not want the process to run, call the instance's CloseMainWindow () or Kill () method to stop the process

 process p = new   Process ();p. Startinfo.filename  =  notepad  Span style= "color: #800000;" >"; //  p.startinfo.arguments = ; //  P.startinfo.windowstyle = processwindowstyle.maximized; //  p.start ();p. WaitForInputIdle (); //waits for the process to start, making sure that the relevant information can be obtained later  

Thread.Sleep (+);
// P.kill (); // P.closemainwindow ();

About two ways to stop a process:

In the case of a graphical interface, calling CloseMainWindow () is the same as clicking the Close button on the graphical interface, which may prompt the user whether to save the data (or call Kill () to exit directly)

If there is no graphical interface, call Kill (), the method does not have any prompt to stop the process directly, any unsaved data during this period will be lost (forcibly terminate the process, the method is asynchronous, so you need to call the instance of the WaitForExit () Or use the HasExited property to confirm that you have exited)

[C # Network application programming] 1, the operation of the process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.