C # winfrom application closes a process in Task Manager

Source: Internet
Author: User

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

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.