This is not true, it is not related to activation of a window. The problem appears when the application is not yet ready to expose the window handle; it's apparent than in early phases of application runtime a window handle is not even created; and, in more rare cases, some applications may change the main window somewhere in the middle of runtime, so there may or may not be a small probability of having this situation in the middle of application runtime.
Please take a look at documentation:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowtitle.aspx[
^].
Even though
InvalidOperationException
is documented as thrown if "MainWindowTitle property is not defined because the process has exited", this documentation is not quite accurate; it may happen in other cases.
So, unfortunately, your code should expect an exception and handle it properly. One suggestion is to try to find the title at later time again, but it will work only for some processes, as some never have such thing.
I should note that the whole idea of filtering running processes by title name is pretty bad. I mean, nothing can guarantee that totally unrelated processes have same main window title name. Unfortunately, the same states fro process names. First of all, I would think hard if you really need such functionality. (In principle, we can discuss it if you explain why would you need it.)
—SA