dotnet / dotnet/dotnet-api-docs

Process.StartTime is documented as not being accessible after the process has exited, but it is

Open
#11,092 1 comment 0 reactions 0 assignees View on GitHub
area-System.Diagnostics.Process untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Code doesn't work

### Description

**From the documentation:**

> [InvalidOperationException](https://learn.microsoft.com/en-us/dotnet/api/system.invalidoperationexception?view=net-9.0)
> The process **has exited.**
>
> -or-
>
> The process has not been started.

However, the following code does not throw an exception:
```C#
Process process = new Process();
process.StartInfo = new ProcessStartInfo(filePath) { UseShellExecute = true };
process.EnableRaisingEvents = true;
process.Exited += (sender, e) =>
{
(sender as Process)?.Refresh();
Console.WriteLine($"Process hasExited: {(sender as Process)?.HasExited}");
Console.WriteLine(
$"Start time in exited event handler: {(sender as Process)?.StartTime}"
);
}
```

Output:
```
Process hasExited: True
Start time in exited event handler: 14.03.2025 9:10:03
```

I believe reliably accessing StartTime after the process has exited would be beneficial. It would allow accurate identification of the process by combining the start time with the PID. Currently, using only the PID is not a reliable identifier for the process once it has exited. While this is how it works now, it does not match the documentation’s description of throwing an InvalidOperationException in this scenario.

### Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.starttime?view=net-9.0#system-diagnostics-process-starttime

### Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Diagnostics/Process.xml

### Document Version Independent Id

5527d631-d1a1-fb6e-8d2e-04438666fb96

### Platform Id

241594df-b4d0-abb5-ce6f-dc2631eec7c4

### Article author

@dotnet-bot

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.