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