C # Process Manager

Source: Internet
Author: User
Code
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using system. diagnostics;
Using system. Threading;
Namespace diagnostics
{
Public partial class Multiprocess: Form
{
Public Multiprocess ()
{
Initializecomponent ();
}

Private void buttonstart_click (Object sender, eventargs E)
{
// Start notepad
Process. startinfo. filename = "notepad.exe ";
Process. Start ();
}

Private void buttonstop_click (Object sender, eventargs E)
{
Process [] myprocess;
// Create a new process Component Array and associate them with all process resources of the specified process name
Myprocess = process. getprocessesbyname ("Notepad ");
Foreach (process instance in myprocess)
{
// Set the number of milliseconds waiting before terminating the current thread
Instance. waitforexit (100 );
Instance. closemainwindow ();
}
}
// Obtain all processes
Private void buttonview_click (Object sender, eventargs E)
{
Listviewprocess. Items. Clear ();
Process [] allprocess;
// Create an array of the Process type and associate them with all processes in the system
Try
{
Allprocess = process. getprocesses ();

Foreach (PROCESS p in allprocess)
{
Listviewitem item = new listviewitem ();
Item. subitems [0]. Text = P. processname. tostring ();
Item. subitems. Add (P. starttime. tow.timestring ());
Item. subitems. Add (P. Id. tostring ());
Item. subitems. Add (P. threads. Count. tostring ());
Listviewprocess. Items. Add (item );
}
}
Catch (system. Exception ee)
{
String A = ee. tostring ();

}

}
// End the process
Private void buttonkill_click (Object sender, eventargs E)
{
Listview. selectedlistviewitemcollection selectitem = listviewprocess. selecteditems;
Foreach (listviewitem item in selectitem)
{
Process killprocess = process. getprocessbyid (convert. toint32 (item. subitems [2]. Text ));
Try
{
Killprocess. Kill ();
MessageBox. Show ("process terminated successfully ");
Buttonview_click (sender, e );
}
Catch (system. Exception ee)
{
String strinfo = ee. tostring ();
MessageBox. Show ("failed to end the process ");
}

}
}
}
}

Engineering documents
/Files/eping/diagnostics.rar

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.