Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Process.ExitTime Property

Gets the time that the associated process exited.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public DateTime ExitTime { get; }
/** @property */
public DateTime get_ExitTime ()

public function get ExitTime () : DateTime

Not applicable.

Property Value

A DateTime that indicates when the associated process was terminated.
Exception typeCondition

PlatformNotSupportedException

The platform is Windows 98 or Windows Millennium Edition (Windows Me), which does not support this property.

NotSupportedException

You are trying to access the ExitTime property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer.

If the process has not terminated, attempting to retrieve the ExitTime property throws an exception. Use HasExited before getting the ExitTime property to determine whether the associated process has terminated.

The following code example creates a process that prints a file. The process raises the Exited event when it exits, and the event handler displays the ExitTime property and other process information.

using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading;
using Microsoft.VisualBasic;

class PrintProcessClass
{

    private Process myProcess = new Process();
    private int elapsedTime;
    private bool eventHandled;

    // Print a file with any known extension.
    public void PrintDoc(string fileName)
    {

        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 (Exception ex)
        {
            Console.WriteLine("An error occurred trying to print \"{0}\":" + "\n" + ex.Message, fileName);
            return;
        }

        // Wait for Exited event, but not more than 30 seconds.
        const int SLEEP_AMOUNT = 100;
        while (!eventHandled)
        {
            elapsedTime += SLEEP_AMOUNT;
            if (elapsedTime > 30000)
            {
                break;
            }
            Thread.Sleep(SLEEP_AMOUNT);
        }
    }

    // Handle Exited event and display process information.
    private void myProcess_Exited(object sender, System.EventArgs e)
    {

        eventHandled = true;
        Console.WriteLine("Exit time:    {0}\r\n" +
            "Exit code:    {1}\r\nElapsed time: {2}", myProcess.ExitTime, myProcess.ExitCode, elapsedTime);
    }

    public static void Main(string[] args)
    {

        // Verify that an argument has been entered.
        if (args.Length <= 0)
        {
            Console.WriteLine("Enter a file name.");
            return;
        }

        // Create the process and print the document.
        PrintProcessClass myProcess = new PrintProcessClass();
        myProcess.PrintDoc(args[0]);
    }
}

  • LinkDemand  for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.