Process.ExitTime 属性

获取关联进程退出的时间。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public ReadOnly Property ExitTime As DateTime
用法
Dim instance As Process
Dim value As DateTime

value = instance.ExitTime
public DateTime ExitTime { get; }
public:
property DateTime ExitTime {
    DateTime get ();
}
/** @property */
public DateTime get_ExitTime ()
public function get ExitTime () : DateTime

属性值

DateTime,它指示关联进程终止的时间。

异常

异常类型 条件

PlatformNotSupportedException

此平台为 Windows 98 或 Windows Millennium Edition (Windows Me),它不支持此属性。

备注

如果进程尚未终止,则试图检索 ExitTime 属性将引发异常。应在获取 ExitTime 属性前使用 HasExited 确定关联进程是否已终止。

示例

下面的代码示例创建打印文件的进程。该进程在退出时将引发 Exited 事件,并且该事件处理程序将显示 ExitTime 属性和其他进程信息。

Imports System
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Threading
Imports Microsoft.VisualBasic

Class PrintProcessClass

    Private WithEvents myProcess As New Process
    Private elapsedTime As Integer
    Private eventHandled As Boolean

    ' Print a file with any known extension.
    Sub PrintDoc(ByVal fileName As String)

        elapsedTime = 0
        eventHandled = False

        Try
            ' Start a process to print a file and raise an event when done.
            myProcess.StartInfo.FileName = fileName
            myProcess.StartInfo.Verb = "Print"
            myProcess.StartInfo.CreateNoWindow = True
            myProcess.EnableRaisingEvents = True
            myProcess.Start()

        Catch ex As Exception
            Console.WriteLine("An error occurred trying to print ""{0}"":" & _
                vbCrLf & ex.Message, fileName)
            Return
        End Try

        ' Wait for Exited event, but not more than 30 seconds.
        Const SLEEP_AMOUNT As Integer = 100
        Do While Not eventHandled
            elapsedTime += SLEEP_AMOUNT
            If elapsedTime > 30000 Then
                Exit Do
            End If
            Thread.Sleep(SLEEP_AMOUNT)
        Loop
    End Sub

    ' Handle Exited event and display process information.
    Private Sub myProcess_Exited(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles myProcess.Exited

        eventHandled = True
        Console.WriteLine("Exit time:    {0}" & vbCrLf & _
            "Exit code:    {1}" & vbCrLf & "Elapsed time: {2}", _
            myProcess.ExitTime, myProcess.ExitCode, elapsedTime)
    End Sub

    Shared Sub Main(ByVal args() As String)

        ' Verify that an argument has been entered.
        If args.Length <= 0 Then
            Console.WriteLine("Enter a file name.")
            Return
        End If

        ' Create the process and print the document.
        Dim myProcess As New PrintProcessClass
        myProcess.PrintDoc(args(0))
    End Sub
End Class

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Process 类
Process 成员
System.Diagnostics 命名空间
Handle
Process.ExitCode 属性