This article describes the start and stop methods of C# implementing process management. Share it for your reference. The specific implementation method is as follows:
using System; using ; using ; using ; using ; using ; using ; using ; //Reference namespaceusing ; using ; namespace StartStopProcess { public partial class Form1 : Form { int fileIndex; string fileName = ""; Process process1 = new Process(); public Form1() { InitializeComponent(); // Display in a detailed list = ; //Parameter meaning: column name, width (pixel), horizontal alignment method ("Process ID", 70, ); ("Process Name", 70, ); ("Eat memory", 70, ); ("Startup time", 70, ); ("file name", 280, ); } private void buttonStart_Click(object sender, EventArgs e) { string argument = + "\\myfile" + fileIndex + ".txt"; if ((argument)==false) { (argument); } //Set the name and parameters of the application to be started ProcessStartInfo ps = new ProcessStartInfo(fileName, argument); = ; fileIndex++; Process p = new Process(); = ps; (); //Waiting for startup to complete, otherwise the process information may fail to obtain (); RefreshListView(); } private void buttonStop_Click(object sender, EventArgs e) { = ; //Create an array of new Process components and associate them with all process resources of the specified process name (Notepad). Process[] myprocesses; myprocesses = ((fileName)); foreach (Process p in myprocesses) { //To achieve the purpose of closing the process by sending a closing message to the main window of the process (); //Wait for 1000 milliseconds (1000); //Release all resources associated with this component (); } fileIndex = 0; RefreshListView(); = ; } private void RefreshListView() { (); //Create arrays of Process type and associate them with all processes in the system Process[] processes; processes = ((fileName)); foreach (Process p in processes) { //Add the process name of each process, the physical memory occupied and the process start time into the listView ListViewItem item = new ListViewItem( new string[]{ (), , ("{0} KB", p.PrivateMemorySize64/1024.0f), ("{0}",), }); (item); } } private void buttonRefresh_Click(object sender, EventArgs e) { RefreshListView(); } private void Form1_Load(object sender, EventArgs e) { } } }
I hope this article will be helpful to everyone's C# programming.