When can Process.Start() return null?
Asked Answered
C

1

12

I have some code that starts a process by using Process.Start(ProcessStartInfo). I see from the documentation that this method can return null if an existing process is reused.

[Returns a] new Process component that is associated with the process resource, or null if no process resource is started (for example, if an existing process is reused).

What does it mean for an existing process to be reused and under what circumstances will this happen?

Consequent answered 11/12, 2014 at 16:12 Comment(1)
See also https://mcmap.net/q/606924/-process-start-returns-nullDefy
S
12

This would happen if you call pass a file (not an EXE), and the file is configured to launch using DDE.

For example, this is how Office applications open files in existing instances.

Spyglass answered 11/12, 2014 at 16:15 Comment(2)
I wondered if it was something along those lines, so I wrote the following test code: var processStartInfo = new ProcessStartInfo(@"C:\test.doc"); var process1 = Process.Start(processStartInfo); var process2 = Process.Start(processStartInfo); process2 was not null, although just the one instance of the document was opened in a single instance of Word. Is it platform or version dependent?Consequent
I've just tried it with a xlsx file. process2 was null. Thanks.Consequent

© 2022 - 2024 — McMap. All rights reserved.