Application of processes in C # (Network Programming)

Source: Internet
Author: User

1. obtain the local string processName; // process name to int processID; // ID int threadNumber; // number of processes TimeSpan cpuTime; // CPU time long processMemory; // Number of memories 2. the framework structure to be implemented (add three menus and one listView). For details about the attribute settings of listView, refer to the application of the control in section C # above: add an event processing function for the three menus, add code: private void creation process ToolStripMenuItem_Click (object sender, EventArgs e) {OpenFileDialog ofDlg = new OpenFileDialog (); // build the Open File Dialog Box ofDlg. filter = "All Executables (*. exe) | *. exe "; // filter if (ofDlg. showDialog () = DialogResult. OK) {try {Process newprocess = Process. start (ofDlg. fileName); // select process} catch (Exception ex) {MessageBox. show (ex. toString () ;}} private void refresh list ToolStripMenuItem_Click (object sender, EventArgs e) {// display process information string processName; // process name is int processID; // ID int threadNumber; // process count TimeSpan cpuTime; // CPU time long processMemory; // Number of memory listView1.Items. clear (); // Clear the original content in the List View Process [] processes = Process. getProcesses (); // defines a dynamic array to obtain all processes in the current system. try {// Add each process project to the list for (int I = 0; I <processes. length; I ++) {processName = processes [I]. processName; processID = processes [I]. id; threadNumber = processes [I]. threads. count; // obtain the number of processes cpuTime = processes [I]. totalProcessorTime; processMemory = processes [I]. workingSet64; string [] subItems = {processName, processID. toString (), threadNumber. toString (), string. format ("{0: 00 }:{}", cpuTime. hours, cpuTime. minutes, cpuTime. seconds), string. format ("{0 :#,#,#} k", processMemory/1024)}; // insert a row of listView1.Items. insert (I, new ListViewItem (subItems) ;}} catch (System. exception ex) {MessageBox. show (ex. message) ;}} private void End Process ToolStripMenuItem_Click (object sender, EventArgs e) {if (listView1.SelectedItems. count> 0) {string str = listView1.SelectedItems [0]. subItems [1]. text; int processID = Int32.Parse (str); // obtain the ID of the selected project. // obtain the Process selectedProcess = Process based on the ID. getProcessById (processID); selectedProcess. kill (); // terminate the process }}

Related Article

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.