-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmProcessMonitor.cs
More file actions
66 lines (58 loc) · 1.66 KB
/
frmProcessMonitor.cs
File metadata and controls
66 lines (58 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using PaJaMa.Common;
using PaJaMa.WinControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaJaMa.Utilities
{
public partial class frmProcessMonitor : Form
{
public frmProcessMonitor()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
refreshGrid();
}
private void refreshGrid()
{
var processes = Process.GetProcesses();
gridMain.DataSource = new SortableBindingList<Process>(processes.OrderBy(p => p.ProcessName).ToList());
//foreach (var col in gridMain.Columns.OfType<DataGridViewColumn>())
//{
// gridMain.Columns[col.Name].SortMode = DataGridViewColumnSortMode.Automatic;
//}
}
private void gridMain_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
gridMain.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = e.Exception.Message;
}
private void btnKill_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to kill selected process?", "Kill", MessageBoxButtons.YesNo)
!= System.Windows.Forms.DialogResult.Yes)
return;
var bw = new BackgroundWorker();
bw.DoWork += delegate (object sender2, DoWorkEventArgs e2)
{
int i = 1;
foreach (DataGridViewRow row in gridMain.SelectedRows)
{
var process = row.DataBoundItem as Process;
bw.ReportProgress(100 * i / gridMain.SelectedRows.Count, "Killing " + process.ProcessName);
process.Kill();
}
};
WinProgressBox.ShowProgress(bw);
refreshGrid();
}
}
}