Process.HasExited プロパティ
アセンブリ: System (system.dll 内)



HasExited の値が true の場合は、関連付けられたプロセスが正常終了または異常終了したことを示します。CloseMainWindow または Kill を呼び出して、関連付けられたプロセスの終了を要求または強制できます。プロセスに対してハンドルが開かれている場合、オペレーティング システムはプロセスの終了時にプロセス メモリを解放しますが、ハンドル、終了コード、終了時刻などの、プロセスに関する管理情報は保持します。この情報を取得するには、ExitCode プロパティと ExitTime プロパティを使用します。これらのプロパティは、このコンポーネントで起動されたプロセスに自動的に設定されます。管理情報は、システム プロセスに関連付けられたすべての Process コンポーネントが破棄され、終了したプロセスを識別するハンドルがなくなったときに解放されます。
プロセスは、コードから独立して終了できます。このコンポーネントを使用してプロセスを起動した場合は、関連付けられたプロセスが独立して終了した場合でも、システムが HasExited の値を自動的に更新します。

メモ帳のインスタンスを起動する例を次に示します。このコードは、インスタンスが起動すると、2 秒間隔で最大 10 秒間、関連付けられているプロセスの物理メモリ使用量を取得します。また、10 秒が経過する前にプロセスが終了したかどうかを検知します。10 秒経過した後もプロセスが実行中である場合は、プロセスを終了します。
Imports System Imports System.Diagnostics Imports System.Threading Namespace Process_Sample Class MyProcessClass Public Shared Sub Main() Try Dim myProcess As Process myProcess = Process.Start("Notepad.exe") ' Display physical memory usage 5 times at intervals of 2 seconds. Dim i As Integer For i = 0 To 4 If not myProcess.HasExited Then ' Discard cached information about the process. myProcess.Refresh() ' Print working set to console. Console.WriteLine("Physical Memory Usage: " + _ myProcess.WorkingSet.ToString()) ' Wait 2 seconds. Thread.Sleep(2000) Else Exit For End If Next i ' Close process by sending a close message to its main window. myProcess.CloseMainWindow() ' Free resources associated with process. myProcess.Close() Catch e As Exception Console.WriteLine("The following exception was raised: ") Console.WriteLine(e.Message) End Try End Sub 'Main End Class 'MyProcessClass End Namespace 'Process_Sample
using System; using System.Diagnostics; using System.Threading; namespace Process_Sample { class MyProcessClass { public static void Main() { try { Process myProcess; myProcess = Process.Start("Notepad.exe"); // Display physical memory usage 5 times at intervals of 2 seconds. for (int i = 0;i < 5; i++) { if (!myProcess.HasExited) { // Discard cached information about the process. myProcess.Refresh(); // Print working set to console. Console.WriteLine("Physical Memory Usage: " + myProcess.WorkingSet.ToString()); // Wait 2 seconds. Thread.Sleep(2000); } else { break; } } // Close process by sending a close message to its main window. myProcess.CloseMainWindow(); // Free resources associated with process. myProcess.Close(); } catch(Exception e) { Console.WriteLine("The following exception was raised: "); Console.WriteLine(e.Message); } } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; int main() { try { Process^ myProcess; myProcess = Process::Start( "Notepad.exe" ); // Display physical memory usage 5 times at intervals of 2 seconds. for ( int i = 0; i < 5; i++ ) { if ( !myProcess->HasExited ) { // Discard cached information about the process. myProcess->Refresh(); // Print working set to console. Console::WriteLine( "Physical Memory Usage : {0}", myProcess->WorkingSet.ToString() ); // Wait 2 seconds. Thread::Sleep( 2000 ); } else { break; } } myProcess->CloseMainWindow(); // Free resources associated with process. myProcess->Close(); } catch ( Exception^ e ) { Console::WriteLine( "The following exception was raised: " ); Console::WriteLine( e->Message ); } }


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からProcess.HasExited プロパティを検索する場合は、下記のリンクをクリックしてください。

- Process.HasExited プロパティのページへのリンク