英語で読む

次の方法で共有


Process.Responding プロパティ

定義

プロセスのユーザー インターフェイスが応答するかどうかを示す値を取得します。

public bool Responding { get; }

プロパティ値

関連付けられたプロセスのユーザー インターフェイスがシステムに応答する場合は true。それ以外の場合は false

例外

この Process オブジェクトに関連付けられているプロセスはありません。

リモート コンピューターで実行されているプロセスの Responding プロパティにアクセスしようとしています。 このプロパティはローカル コンピューターで実行中のプロセスに対してのみ使用可能です。

次の例では、メモ帳のインスタンスを開始します。 次に、この例では、関連付けられているプロセスのさまざまなプロパティを取得して表示します。 この例では、プロセスが終了したときにを検出し、プロセスの終了コードを表示します。

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}");
            }
        }
    }
}

注釈

このプロパティによって返される値は、最近更新された状態を表します。 最新の状態を取得するには、まずメソッドを呼び出す Refresh() 必要があります。

プロセスにユーザー インターフェイスがある場合、プロパティは Responding ユーザー インターフェイスに接続して、プロセスがユーザー入力に応答しているかどうかを判断します。 インターフェイスがすぐに応答しない場合、 プロパティは を Responding 返します false。 関連付けられたプロセスのインターフェイスが応答を停止したかどうかを確認するには、このプロパティを使用します。

プロセスに がない場合、 MainWindowHandleこのプロパティは を返します true

適用対象

こちらもご覧ください