網站首頁 編程語言 正文
實踐過程
效果
代碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void getProcessInfo()
{
try
{
listView1.Items.Clear();
Process[] MyProcesses = Process.GetProcesses();
tsslInfo.Text = "進程總數:" + MyProcesses.Length.ToString();
string[] Minfo = new string[6];
foreach (Process MyProcess in MyProcesses)
{
Minfo[0] = MyProcess.ProcessName;
Minfo[1] = MyProcess.MainModule.ModuleName;
Minfo[2] = MyProcess.Threads.Count.ToString();
Minfo[3] = MyProcess.BasePriority.ToString();
Minfo[4] = Convert.ToString(MyProcess.WorkingSet / 1024) + "K";
Minfo[5] = Convert.ToString(MyProcess.VirtualMemorySize / 1024) + "K";
ListViewItem lvi = new ListViewItem(Minfo, "process");
listView1.Items.Add(lvi);
}
}
catch { }
}
private void Form1_Load(object sender, EventArgs e)
{
getProcessInfo();
}
private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
{
getProcessInfo();
}
private void 結束進程ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (MessageBox.Show("警告:終止進程會導致不希望發生的結果,\r包括數據丟失和系統不穩定。在被終止前,\r進程將沒有機會保存其狀態和數據。確實\r想終止該進程嗎?", "任務管理器警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
string ProcessName = listView1.SelectedItems[0].Text;
Process[] MyProcess = Process.GetProcessesByName(ProcessName);
MyProcess[0].Kill();
getProcessInfo();
}
else
{ }
}
catch
{
string ProcessName = listView1.SelectedItems[0].Text;
Process[] MyProcess1 = Process.GetProcessesByName(ProcessName);
Process MyProcess = new Process();
//設定程序名
MyProcess.StartInfo.FileName = "cmd.exe";
//關閉Shell的使用
MyProcess.StartInfo.UseShellExecute = false;
//重定向標準輸入
MyProcess.StartInfo.RedirectStandardInput = true;
//重定向標準輸出
MyProcess.StartInfo.RedirectStandardOutput = true;
//重定向錯誤輸出
MyProcess.StartInfo.RedirectStandardError = true;
//設置不顯示窗口
MyProcess.StartInfo.CreateNoWindow = true;
//執行強制結束命令
MyProcess.Start();
MyProcess.StandardInput.WriteLine("ntsd -c q -p " + (MyProcess1[0].Id).ToString());
MyProcess.StandardInput.WriteLine("Exit");
getProcessInfo();
}
}
private void SetBasePriority(int i)
{
string ProcessName = listView1.SelectedItems[0].Text;
Process[] MyProcess = Process.GetProcessesByName(ProcessName);
switch (i)
{
case 0: MyProcess[0].PriorityClass = ProcessPriorityClass.Idle; break;//低
case 1: MyProcess[0].PriorityClass = ProcessPriorityClass.Normal; break;//標準
case 2: MyProcess[0].PriorityClass = ProcessPriorityClass.High; break;//高
case 3: MyProcess[0].PriorityClass = ProcessPriorityClass.RealTime; break;//實時
case 4: MyProcess[0].PriorityClass = ProcessPriorityClass.AboveNormal; break;//高于標準
case 5: MyProcess[0].PriorityClass = ProcessPriorityClass.BelowNormal; break;//低于標準
}
getProcessInfo();
}
private void 實時ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(3);
}
private void 高ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(2);
}
private void 高于標準ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(4);
}
private void 標準ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(1);
}
private void 低于標準ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(5);
}
private void 低ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetBasePriority(0);
}
}
partial class Form1
{
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
/// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.刷新ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.結束進程ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.設置優先級ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.實時ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.高ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.高于標準ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.標準ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.低于標準ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.低ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader11 = new System.Windows.Forms.ColumnHeader();
this.columnHeader12 = new System.Windows.Forms.ColumnHeader();
this.columnHeader13 = new System.Windows.Forms.ColumnHeader();
this.columnHeader14 = new System.Windows.Forms.ColumnHeader();
this.columnHeader15 = new System.Windows.Forms.ColumnHeader();
this.columnHeader16 = new System.Windows.Forms.ColumnHeader();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.tsslInfo = new System.Windows.Forms.ToolStripStatusLabel();
this.contextMenuStrip1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.刷新ToolStripMenuItem,
this.結束進程ToolStripMenuItem,
this.設置優先級ToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
this.contextMenuStrip1.ShowImageMargin = false;
this.contextMenuStrip1.ShowItemToolTips = false;
this.contextMenuStrip1.Size = new System.Drawing.Size(106, 70);
//
// 刷新ToolStripMenuItem
//
this.刷新ToolStripMenuItem.Name = "刷新ToolStripMenuItem";
this.刷新ToolStripMenuItem.Size = new System.Drawing.Size(105, 22);
this.刷新ToolStripMenuItem.Text = "刷新";
this.刷新ToolStripMenuItem.Click += new System.EventHandler(this.刷新ToolStripMenuItem_Click);
//
// 結束進程ToolStripMenuItem
//
this.結束進程ToolStripMenuItem.Name = "結束進程ToolStripMenuItem";
this.結束進程ToolStripMenuItem.Size = new System.Drawing.Size(105, 22);
this.結束進程ToolStripMenuItem.Text = "結束進程";
this.結束進程ToolStripMenuItem.Click += new System.EventHandler(this.結束進程ToolStripMenuItem_Click);
//
// 設置優先級ToolStripMenuItem
//
this.設置優先級ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.實時ToolStripMenuItem,
this.高ToolStripMenuItem,
this.高于標準ToolStripMenuItem,
this.標準ToolStripMenuItem,
this.低于標準ToolStripMenuItem,
this.低ToolStripMenuItem});
this.設置優先級ToolStripMenuItem.Name = "設置優先級ToolStripMenuItem";
this.設置優先級ToolStripMenuItem.Size = new System.Drawing.Size(105, 22);
this.設置優先級ToolStripMenuItem.Text = "設置優先級";
//
// 實時ToolStripMenuItem
//
this.實時ToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.實時ToolStripMenuItem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.實時ToolStripMenuItem.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
this.實時ToolStripMenuItem.Name = "實時ToolStripMenuItem";
this.實時ToolStripMenuItem.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.實時ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.實時ToolStripMenuItem.Text = "實時";
this.實時ToolStripMenuItem.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.實時ToolStripMenuItem.Click += new System.EventHandler(this.實時ToolStripMenuItem_Click);
//
// 高ToolStripMenuItem
//
this.高ToolStripMenuItem.Name = "高ToolStripMenuItem";
this.高ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.高ToolStripMenuItem.Text = "高";
this.高ToolStripMenuItem.Click += new System.EventHandler(this.高ToolStripMenuItem_Click);
//
// 高于標準ToolStripMenuItem
//
this.高于標準ToolStripMenuItem.Name = "高于標準ToolStripMenuItem";
this.高于標準ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.高于標準ToolStripMenuItem.Text = "高于標準";
this.高于標準ToolStripMenuItem.Click += new System.EventHandler(this.高于標準ToolStripMenuItem_Click);
//
// 標準ToolStripMenuItem
//
this.標準ToolStripMenuItem.Name = "標準ToolStripMenuItem";
this.標準ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.標準ToolStripMenuItem.Text = "標準";
this.標準ToolStripMenuItem.Click += new System.EventHandler(this.標準ToolStripMenuItem_Click);
//
// 低于標準ToolStripMenuItem
//
this.低于標準ToolStripMenuItem.Name = "低于標準ToolStripMenuItem";
this.低于標準ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.低于標準ToolStripMenuItem.Text = "低于標準";
this.低于標準ToolStripMenuItem.Click += new System.EventHandler(this.低于標準ToolStripMenuItem_Click);
//
// 低ToolStripMenuItem
//
this.低ToolStripMenuItem.Name = "低ToolStripMenuItem";
this.低ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
this.低ToolStripMenuItem.Text = "低";
this.低ToolStripMenuItem.Click += new System.EventHandler(this.低ToolStripMenuItem_Click);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(469, 314);
this.tabControl1.TabIndex = 6;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.listView1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(461, 289);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "進程";
this.tabPage1.UseVisualStyleBackColor = true;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader11,
this.columnHeader12,
this.columnHeader13,
this.columnHeader14,
this.columnHeader15,
this.columnHeader16});
this.listView1.ContextMenuStrip = this.contextMenuStrip1;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(3, 3);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(455, 283);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader11
//
this.columnHeader11.Text = "映像名稱";
this.columnHeader11.Width = 100;
//
// columnHeader12
//
this.columnHeader12.Text = "進程ID";
this.columnHeader12.Width = 70;
//
// columnHeader13
//
this.columnHeader13.Text = "線程數";
this.columnHeader13.Width = 70;
//
// columnHeader14
//
this.columnHeader14.Text = "優先級";
//
// columnHeader15
//
this.columnHeader15.Text = "物理內存";
this.columnHeader15.Width = 65;
//
// columnHeader16
//
this.columnHeader16.Text = "虛擬內存";
this.columnHeader16.Width = 85;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsslInfo});
this.statusStrip1.Location = new System.Drawing.Point(0, 314);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(469, 22);
this.statusStrip1.TabIndex = 7;
this.statusStrip1.Text = "statusStrip1";
//
// tsslInfo
//
this.tsslInfo.Name = "tsslInfo";
this.tsslInfo.Size = new System.Drawing.Size(131, 17);
this.tsslInfo.Text = "toolStripStatusLabel1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(469, 336);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.statusStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "進程管理器";
this.Load += new System.EventHandler(this.Form1_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem 刷新ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 結束進程ToolStripMenuItem;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader11;
private System.Windows.Forms.ColumnHeader columnHeader12;
private System.Windows.Forms.ColumnHeader columnHeader13;
private System.Windows.Forms.ColumnHeader columnHeader14;
private System.Windows.Forms.ColumnHeader columnHeader15;
private System.Windows.Forms.ColumnHeader columnHeader16;
private System.Windows.Forms.ToolStripMenuItem 設置優先級ToolStripMenuItem;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel tsslInfo;
private System.Windows.Forms.ToolStripMenuItem 實時ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 高ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 高于標準ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 標準ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 低于標準ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 低ToolStripMenuItem;
}
原文鏈接:https://blog.csdn.net/qq_27489007/article/details/128305866
相關推薦
- 2023-05-08 Android事件分發之View事件處理關鍵及示例分析_Android
- 2022-06-24 使用ASP.NET?Web?API構建Restful?API_實用技巧
- 2023-04-18 Python實現常見的4種坐標互相轉換_python
- 2023-02-05 c++?梅森數源碼示例解析_C 語言
- 2022-10-04 Qt計時器使用方法詳解_C 語言
- 2022-12-01 解決k8s?namespace?一直處于?Terminating?狀態的問題_云其它
- 2023-03-13 Pandas篩選某列過濾的方法_python
- 2022-09-29 python繪制直方圖的方法_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支