中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

C#獲取進(jìn)程或線程的相關(guān)信息-創(chuàng)新互聯(lián)

信息來自: http://blog.163.com/kunkun0921@126/blog/static/169204332201293023432113/C#獲取進(jìn)程或線程的相關(guān)信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApp
{
class ProcessDo
    {
/// <summary>   /// 獲取進(jìn)程相關(guān)信息
/// </summary>   public static void GetProcessInfomation()
        {
            Process pro= Process.GetProcessesByName("QQ")[0];
            Console.WriteLine("進(jìn)程名稱:" + pro.ProcessName);
            Console.WriteLine("進(jìn)程ID:" + pro.Id.ToString());
            Console.WriteLine("啟動時間:" + pro.StartTime.ToLongDateString() + pro.StartTime.ToLongTimeString());
            Console.WriteLine("是否響應(yīng):" + pro.Responding.ToString());
            Console.WriteLine("關(guān)聯(lián)進(jìn)程句柄:" + pro.Handle.ToString());
            Console.WriteLine("進(jìn)程打開的句柄數(shù):" + pro.HandleCount.ToString());
            Console.WriteLine("主窗口句柄:" + pro.MainWindowHandle.ToString());
            Console.WriteLine("主窗口標(biāo)題:" + pro.MainWindowTitle);
            Console.WriteLine("模塊數(shù)量:" + pro.Modules.Count.ToString());
            Console.WriteLine("基本優(yōu)先級:" + pro.BasePriority.ToString());
            Console.WriteLine("提升優(yōu)先級:" + pro.PriorityBoostEnabled.ToString());
            Console.WriteLine("處理器:" + pro.ProcessorAffinity.ToInt32().ToString());
            Console.WriteLine("最小工作集:" + pro.MinWorkingSet.ToInt32().ToString());
            Console.WriteLine("大工作集:" + pro.MaxWorkingSet.ToInt32().ToString());
            Console.WriteLine("工作集:" + pro.WorkingSet.ToString());
            Console.WriteLine("峰值工作集:" + pro.PeakWorkingSet.ToString());
            Console.WriteLine("專用內(nèi)存大小:" + pro.PrivateMemorySize.ToString());
            Console.WriteLine("未分頁內(nèi)存大?。? + pro.NonpagedSystemMemorySize.ToString());
            Console.WriteLine("分頁內(nèi)存大小:" + pro.PagedMemorySize.ToString());
            Console.WriteLine("峰值分頁內(nèi)存大?。? + pro.PeakPagedMemorySize.ToString());
            Console.WriteLine("虛擬內(nèi)存大?。? + pro.VirtualMemorySize.ToString());
            Console.WriteLine("峰值虛擬內(nèi)存大小:" + pro.PeakVirtualMemorySize.ToString());
            Console.WriteLine("占用時間:" + pro.TotalProcessorTime.ToString());
            Console.WriteLine("特權(quán)占用時間:" + pro.PrivilegedProcessorTime.ToString());
            Console.WriteLine("用戶占用時間:" + pro.UserProcessorTime.ToString());

        }


/// <summary>   /// 進(jìn)程的線程詳細(xì)信息
/// </summary>   public static void GetProcessThreadInfomation()
        {
            Process pro= Process.GetProcessesByName("QQ")[0];
            Console.WriteLine("QQ程序進(jìn)程的線程詳細(xì)信息如下:");
int length = pro.Threads.Count;
for (int i = 0; i < length; i++)
            {
var thread = pro.Threads[i];
                Console.WriteLine("標(biāo)識符:" + thread.Id.ToString());
                Console.WriteLine("基本優(yōu)先級:" + thread.BasePriority.ToString());
                Console.WriteLine("當(dāng)前優(yōu)先級:" + thread.CurrentPriority.ToString());
                Console.WriteLine("內(nèi)存地址:" + thread.StartAddress.ToInt32());
                Console.WriteLine("啟動時間:" + thread.StartTime.ToString());
                Console.WriteLine("使用時間:" + thread.UserProcessorTime.ToString());
                Console.Write("當(dāng)前狀態(tài):");
switch (thread.ThreadState)
                {
case ThreadState.Initialized:
                        Console.WriteLine("線程已經(jīng)初始化但尚未啟動");
break;
case ThreadState.Ready:
                        Console.WriteLine("線程準(zhǔn)備在下一個可用的處理器上運行");
break;
case ThreadState.Running:
                        Console.WriteLine("當(dāng)前正在使用處理器");
break;
case ThreadState.Standby:
                        Console.WriteLine("線程將要使用處理器");
break;
case ThreadState.Terminated:
                        Console.WriteLine("線程已完成執(zhí)行并退出"); 
break;
case ThreadState.Transition:
                        Console.WriteLine("線程在可以執(zhí)行錢等待處理器之外的資源");
break;
case ThreadState.Unknown:
                        Console.WriteLine("狀態(tài)未知");
break;
case ThreadState.Wait:
                        Console.WriteLine("正在等待外圍操作完成或者資源釋放");
break;
default:
break;
                }
if (thread.ThreadState == ThreadState.Wait)
                {

                    Console.Write("等待原因:");
switch (thread.WaitReason)
                    {
case ThreadWaitReason.EventPairHigh:
                            Console.WriteLine("線程正在等待事件對高");
break;
case ThreadWaitReason.EventPairLow:
                            Console.WriteLine("線程正在等待事件對低");
break;
case ThreadWaitReason.ExecutionDelay:
                            Console.WriteLine("線程執(zhí)行延遲");
break;
case ThreadWaitReason.Executive:
                            Console.WriteLine("線程正在等待計劃程序");
break;
case ThreadWaitReason.FreePage:
                            Console.WriteLine("線程正在等待可用的虛擬內(nèi)存頁");
break;
case ThreadWaitReason.LpcReceive:
                            Console.WriteLine("線程正在等待本地過程調(diào)用到達(dá)");
break;
case ThreadWaitReason.LpcReply:
                            Console.WriteLine("線程正在等待對本地過程調(diào)用的回復(fù)到達(dá)");
break;
case ThreadWaitReason.PageIn:
                            Console.WriteLine("線程正在等待虛擬內(nèi)存頁到達(dá)內(nèi)存");
break;
case ThreadWaitReason.PageOut:
                            Console.WriteLine("線程正在等待虛擬內(nèi)存頁寫入磁盤");
break;
case ThreadWaitReason.Suspended:
                            Console.WriteLine("線程執(zhí)行暫停");
break;
case ThreadWaitReason.SystemAllocation:
                            Console.WriteLine("線程正在等待系統(tǒng)分配");
break;
case ThreadWaitReason.Unknown:
                            Console.WriteLine("線程因位置原因而等待");
break;
case ThreadWaitReason.UserRequest:
                            Console.WriteLine("線程正在等待用戶請求");
break;
case ThreadWaitReason.VirtualMemory:
                            Console.WriteLine("線程正在等待系統(tǒng)分配虛擬內(nèi)存");
break;
default:
break;
                    }
                }
                Console.WriteLine();
             }
        }

/// <summary>   /// 限制應(yīng)用程序運行時間
/// 即關(guān)聯(lián)程序超出設(shè)置的運行將自動關(guān)閉
/// </summary>   public static void GetKillAppForWaitTime()
        {
            Process proc= new Process();
            proc.StartInfo= new ProcessStartInfo(@"C:Documents and Settingszkk桌面mysql_20120925.sql");
//啟動應(yīng)用程序            proc.Start();
//等待程序師徒完成載入            proc.WaitForInputIdle();
//等待程序結(jié)束執(zhí)行            proc.WaitForExit(3000);
//如果程序在時間期限之前關(guān)閉,HasExited將會是true if (proc.HasExited == false)
            {
//測試程序是否已經(jīng)停止回應(yīng)  if (proc.Responding)
                {
//程序有回應(yīng),關(guān)閉主視圖                    proc.CloseMainWindow();
                }
else
                {
//如果程序沒有回應(yīng),將強制關(guān)閉                    proc.Kill();
                }
            }
        }
    }
}

網(wǎng)站欄目:C#獲取進(jìn)程或線程的相關(guān)信息-創(chuàng)新互聯(lián)
分享路徑:http://www.rwnh.cn/article34/ddcese.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、云服務(wù)器電子商務(wù)、ChatGPT、品牌網(wǎng)站制作、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)
富民县| 白水县| 屏东县| 环江| 辰溪县| 吐鲁番市| 岗巴县| 塔河县| 肥东县| 鹤山市| 龙海市| 东台市| 怀来县| 临颍县| 江阴市| 梅河口市| 铜陵市| 宝鸡市| 东乌| 浙江省| 库车县| 汉川市| 彰武县| 文昌市| 渑池县| 吴桥县| 乌兰察布市| 乳源| 离岛区| 桓仁| 襄汾县| 灵寿县| 达日县| 盐源县| 岫岩| 杨浦区| 成武县| 玉门市| 广平县| 昌吉市| 额济纳旗|