'Does Process.Refresh() ever happen automatically?

I ran this code:

        System.Diagnostics.Process qwProcess;
        // Assign and start qwProcess and do other stuff
        qwProcess.Refresh();
        LogActivity.LogThis($"qwProcess found: id={qwProcess.Id}, exited={qwProcess.HasExited}");
        if (!qwProcess.HasExited)
        {
            LogActivity.LogThis($"Attempting to kill qwProcess");
            qwProcess.Kill();
        }
        else
        {
            LogActivity.LogThis($"QW Process ({qwProcess.Id}) had exited so no attempt made to force.");
        }

and was surprised to see this output in the Log

qwProcess found: id=4828, exited=False
QW Process (4828) had exited so no attempt made to force.

From the documentation, I expected Refresh() to cache the values of all Process properties until another Refresh() call, but in order to enter the else{} block, the value of HasExited must have changed after the first log entry. Is this expected behaviour?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source