I am interested if calling Process.Refresh() is mandatory when waiting for the process to terminate by checking Process.HasFinished property?
I have a piece of code that works fine without the Process.Refresh() call, however I am curious weather this is a coincidence? I can see that a msdn example has the Process.Refresh() call…
If its not necessary, and Process.HasExited is the only property I need, are there any advantages to making the call to Process.Refresh() ? If not, is there a reason it is in the msdn example?
Thank you for your answers.
as you’ve noticed, MSDN doesn’t exactly specify, what information is cached and thus needs to be refreshed using
Process.Refresh().After a short (and probably incomplete) analysis of the class using reflector it seems though, that the
HasExitedproperty is “calculated” every time it’s accessed.Refreshseems mostly to force an update of the internalProcessInfoobject, which contains information such as memory consumption, handle information etc.On the other hand,
Refreshdoesn’t really fetch all this information, it simply discards the internal cache. The information is only refetched when you access any of the properties. SoRefreshhas practically no performance overhead.Therefore it might be more secure to call
Refreshjust in case Microsoft decides to change theHasExitedimplementation in the future.