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;Namespace processkill{PublicPartialClassForm1:Form {Public System.Threading.Thread MyThread;Public Form1 () {InitializeComponent (); MyThread =New System.Threading.Thread (New System.Threading.ThreadStart (kill_process));Initialize thread, execute Close Process method kill_process (); Mythread.start (); }Privatevoid Button1_Click (Object sender,EventArgs e) {getgetprocesses (); }///<summary>///Call this method to see all the processes that are currently running on this computer///</summary>Privatevoid Getgetprocesses () {listView1.Items.Clear ();process[] List =Process.getprocesses (".");Get all the processes currently running on this machinefor (int i = 0; I < list. Length; i++)Loop Add process information {Listview1.view =View.Details;Display mode for columnsListViewItem LVI =NewListViewItem (NewString[] {list[i]. ProcessName, List[i]. Id.tostring (), List[i]. Privatememorysize64.tostring ()}); LISTVIEW1.ITEMS.ADD (LVI); } }Privatevoid Listview1_selectedindexchanged (Object sender,EventArgs e) {}///<summary>///Close process///</summary>void Kill_process () {var killlist = System.Configuration.configurationmanager.appsettings["Killname"]. ToString (). Split (‘,‘);Gets the name of the process set in App.cong that needs to be closedprocess[] List =Process.getprocesses (".");Get all the processes currently running on this machineforeach (VAR itemIn Killlist)Traverse to see if the process exists {foreach (Process PRIn list) {if (item = = pr. ProcessName) {pr. Kill (); } } }Application.exit (); System.Environment.exit (System.Environment.exitcode);Close own Process}private void button2_click (object sender, EventArgs e) {kill_process (); Getgetprocesses (); the private void Form1_Load (object sender, EventArgs e) {}}} is /c3>
C # winfrom application closes a process in Task Manager