How do I determine if a process is associated with a System.Diagnostics.Process object?

c#, process

Solution

Have you tried checking `Process.Id` and one of the Exit properties ?

Ref.

In response to poster's comments: perhaps you will have to wrap in a try/catch and an exception being thrown indicates not started? It's not pretty!

Problem

Given a particular System.Diagnostics.Process that has been assigned values to its properties `.FileName` and `.Arguments`, what is the best way to determine if it: - has ever been issued a `.Start()` command or - is currently associated with a process at all? If `.Start()` was never issued, then calling `.CloseMainWindow()` causes an InvalidOperationException, which I'd like to avoid.

Original source