using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
Process[] myprocess = Process.GetProcesses();
string[] info = new string[6];
listView1.Columns.Add("name", 150, HorizontalAlignment.Left);
listView1.Columns.Add("ID", 150, HorizontalAlignment.Left);
listView1.Columns.Add("thread", 150, HorizontalAlignment.Left);
listView1.Columns.Add("priority", 150, HorizontalAlignment.Left);
listView1.Columns.Add("memory", 150, HorizontalAlignment.Left);
listView1.Columns.Add("virual memory", 150, HorizontalAlignment.Left);
ListViewItem myitem;
foreach (Process p in myprocess)
{
info[0] = p.ProcessName;
info[1] = p.Id.ToString();
info[2] = p.Threads.Count.ToString();
info[3] = p.BasePriority.ToString();
info[4] = Convert.ToString(p.WorkingSet64 / 1024) + "k";
info[5] = Convert.ToString(p.VirtualMemorySize64 / 1024) + "k";
myitem = new ListViewItem(info[0], 0);
myitem.SubItems.Add(info[1]);
myitem.SubItems.Add(info[2]);
myitem.SubItems.Add(info[3]);
myitem.SubItems.Add(info[4]);
myitem.SubItems.Add(info[5]);
listView1.Items.Add(myitem);
//listBox1.Items.Add(info[0]);
}
}
private string slv;
private void button2_Click(object sender, EventArgs e)
{
/* if (listBox1.SelectedItems.Count > 0)
{
MessageBox.Show(listBox1.SelectedItem.ToString());
Process[] p = Process.GetProcessesByName(listBox1.SelectedItem.ToString().Trim());
foreach (Process x in p)
{
x.CloseMainWindow();
}
}*/
/* MessageBox.Show(slv);
if (listView1.SelectedItems.Count > 0)
{
Process[] p = Process.GetProcessesByName(slv);
foreach (Process x in p)
{
x.CloseMainWindow();
}
}*/
listView1.Clear();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 1)
{
slv = listView1.SelectedItems[0].ToString().TrimStart('L', 'i', 's', 't', 'V', 'e', 'w', 'I', 'm', ':');
slv = slv.TrimStart(' ', '{');
slv = slv.TrimEnd(' ', '}');
}
}
private void aToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(slv);
if (listView1.SelectedItems.Count > 0)
{
Process[] p = Process.GetProcessesByName(slv);
p[0].Kill();
}
}
private void idleToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
Process[] p = Process.GetProcessesByName(slv);
p[0].PriorityClass = ProcessPriorityClass.Idle;
}
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
Process[] p = Process.GetProcessesByName(slv);
p[0].PriorityClass = ProcessPriorityClass.Normal;
}
}
private void highToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
Process[] p = Process.GetProcessesByName(slv);
p[0].PriorityClass = ProcessPriorityClass.High;
}
}
}
}
No comments:
Post a Comment