• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#一个进程监控另一进程的用户界面是否响应系统

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

定义

获取指示进程的用户界面当前是否响应的值。

获取指示进程的用户界面当前是否响应的值。


public bool Responding { get; }

属性值

false。

异常

false,以在 Windows 98 和 Windows Me 上访问此属性。

Process 对象关联的进程。

此属性仅可用于本地计算机上运行的进程。

示例

该示例检测时在进程退出,并显示该进程的退出代码。

using System;
using System.Diagnostics;

namespace ProcessSample
{
    class ProcessMonitorSample
    {
        public static void Main()
        {
            // Define variables to track the peak
            // memory usage of the process.
            long peakPagedMem   = 0,
                 peakWorkingSet = 0,
                 peakVirtualMem = 0;

            // Start the process.
            using (Process myProcess = Process.Start("NotePad.exe"))
            {
                // Display the process statistics until
                // the user closes the program.
                do
                {
                    if (!myProcess.HasExited)
                    {
                        // Refresh the current process property values.
                        myProcess.Refresh();

                        Console.WriteLine();

                        // Display current process statistics.

                        Console.WriteLine($"{myProcess} -");
                        Console.WriteLine("-------------------------------------");

                        Console.WriteLine($"  Physical memory usage     : {myProcess.WorkingSet64}");
                        Console.WriteLine($"  Base priority             : {myProcess.BasePriority}");
                        Console.WriteLine($"  Priority class            : {myProcess.PriorityClass}");
                        Console.WriteLine($"  User processor time       : {myProcess.UserProcessorTime}");
                        Console.WriteLine($"  Privileged processor time : {myProcess.PrivilegedProcessorTime}");
                        Console.WriteLine($"  Total processor time      : {myProcess.TotalProcessorTime}");
                        Console.WriteLine($"  Paged system memory size  : {myProcess.PagedSystemMemorySize64}");
                        Console.WriteLine($"  Paged memory size         : {myProcess.PagedMemorySize64}");

                        // Update the values for the overall peak memory statistics.
                        peakPagedMem   = myProcess.PeakPagedMemorySize64;
                        peakVirtualMem = myProcess.PeakVirtualMemorySize64;
                        peakWorkingSet = myProcess.PeakWorkingSet64;

                        if (myProcess.Responding)
                        {
                            Console.WriteLine("Status = Running");
                        }
                        else
                        {
                            Console.WriteLine("Status = Not Responding");
                        }
                    }
                }
                while (!myProcess.WaitForExit(1000));


                Console.WriteLine();
                Console.WriteLine($"  Process exit code          : {myProcess.ExitCode}");

                // Display peak memory statistics for the process.
                Console.WriteLine($"  Peak physical memory usage : {peakWorkingSet}");
                Console.WriteLine($"  Peak paged memory usage    : {peakPagedMem}");
                Console.WriteLine($"  Peak virtual memory usage  : {peakVirtualMem}");
            }
        }
    }
}

 

注解

使用此属性确定关联的进程的界面已停止响应。

MainWindowHandle,此属性返回true

应用示例

 1  public static void Main(string[] args)
 2         {
 3             Process[] process = Process.GetProcessesByName("应用程序进程名");
 4            
 5             if (process.Length > 0)
 6             {
 7                 Process myProcess = process[0];
 8 
 9                 do
10                 {
11                     if (!myProcess.HasExited)
12                     {
13                         myProcess.Refresh();
14                         if (myProcess.Responding)
15                         {
16                             //Console.WriteLine("Status = Running");
17                         }
18                         else
19                         {
20                             //Console.WriteLine("Status = Not Responding");
21                             //无响应处理过程。。。。
22                            
23                         }
24                     }
25                 }
26                 while (!myProcess.WaitForExit(ReadWatchTime()));
27             }
28         }
View Code

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#查找string数组的某一个值的索引发布时间:2022-07-10
下一篇:
c#如何实现自动更新发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap