C # Programming Application-Process Management

Source: Internet
Author: User

I haven't touched C # development for more than a year. I 'd like to review winform knowledge:

 

C # enable and disable processes to obtain the process list;

 

There is a picture with the truth:

 

 

1 Using System;
2 Using System. Collections. Generic;
3 Using System. componentmodel;
4 Using System. Data;
5 Using System. drawing;
6 Using System. text;
7 Using System. Windows. forms;
8 Using System. diagnostics;
9 Using System. Threading;
10
11 Namespace Processexample
12 {
13
14 Public Partial Class Form1: Form
15 {
16
17 Public Form1 ()
18 {
19 Initializecomponent ();
20 }
21
22 Private Void Buttonstart_click ( Object Sender, eventargs E)
23 {
24 Process1.startinfo. filename = " Notepad.exe " ;
25 // Start the notepad.exe process.
26 Process1.start ();
27 }
28 Private Void Buttonstop_click ( Object Sender, eventargs E)
29 {
30 // Create an array of new process components and associate them with all process resources of the specified process name (Notepad.
31 Process [] myprocesses;
32 Myprocesses = process. getprocessesbyname ( " Notepad " );
33 Foreach (Process instance In Myprocesses)
34 {
35 // Set to wait 1000 milliseconds before terminating the current thread
36 Instance. waitforexit ( 1000 );
37 Instance. closemainwindow ();
38 }
39 }
40 Private Void Buttonview_click ( Object Sender, eventargs E)
41 {
42 Listbox1.items. Clear ();
43 // Create an array of the Process type and associate them with all processes in the system.
44 Process [] processes;
45 Processes = process. getprocesses ();
46 Foreach (PROCESS p In Processes)
47 {
48 // Idle indicates the name of the process that displays the CPU idle rate.
49 // The starttime of the access to idle is abnormal, so it is excluded.
50 If (P. processname! = " Idle " )
51 {
52 // Add each process name and process start time to listbox1
53 This . Listbox1.items. Add (
54 String . Format ( " {0,-30} {1: H: M: s} " , P. processname, P. starttime ));
55 }
56 }
57 }
58 }
59 }

 

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.