1

I have an application that I am deploying using ClickOnce. I am using the default InstallUpdateUpdateSyncWithInfo() method provided here. I made two changes though; I made the method public and static as I am calling it from a static class. I know bad practices. This is some lazy code just to try out ClickOnce.

Everytime the application updates it loads two instances, the old one and the new one.

Other than that though I am calling the method in my app.xaml.cs like this:

public partial class App : Application
{
    private void Application_Startup(object sender, StartupEventArgs e)
    {
        MainWindow window = new MainWindow();
        CheckForUpdates.InstallUpdateSyncWithInfo();
        window.Show();
    }
}

I thought if I call Window.Show() after checking for an Update it would call the Application.Restart() method in InstallUpdateUpdateSyncWithInfo() before the old version could load, but this is not the case.

Does anyone know how I can prevent two instances of my application from loading after the application is updated?

There was another post on Stack Overflow which from the title, I thought would directly address this question, but I did not see how the poster modified his code to prevent two instances from loading.

4

1 回答 1

2

无需自己编写自动更新代码。首先,我会删除您的更新代码。

接下来右键单击您的 C# 项目并选择Properties. 然后转到Publish并单击Updates...。勾选复选框,以便您的应用程序检查更新,而 ClickOnce 将处理其余部分。

于 2014-09-03T21:31:40.130 回答