FileVersionInfo.GetVersionInfo getting old version of an exe swapped at runtime
<p>I have a program executing in c# that is sometimes updated while it is running by swapping the exe to a new one. I want the program to routinely check if it has been updated and if so, restart. I use the following function to do this.</p>

<pre><code>    public static bool DoINeedToRestart(string exe_name)
    {

        Version cur_version = new Version(MainProgram.StartVersion);
        Version file_version = new Version(GetProductVersion(exe_name));
        MessageBox.Show("Comparing cur_version " + cur_version.ToString() + " with " + file_version.ToString());
        if (file_version &gt; cur_version)
        {
            return true;
        }
        return false;
    }

    public static string GetProductVersion(string path_name)
    {
            FileVersionInfo myFI = FileVersionInfo.GetVersionInfo(path_name);
            return myFI.FileVersion;
    }
</code></pre>

<p>MainProgram.StartVersion is set when the program is started to be the current version using the GetProductVersion(exe_name)</p>

<p>exe_name is set to be the name of the executable that is being updated. </p>

<p>The problem I have is once the MainProgram.exe file has been updated (I verify this manually by looking at the file properties and checking the file version), the GetProductVersion still returns the old file version and I have no idea why! Any help is greatly appreciated. I'm running Windows Vista with .Net 3.5.</p>
