Restart WPF application after click-once update (start the new version) Restart WPF application after click-once update (start the new version) wpf wpf

Restart WPF application after click-once update (start the new version)


There are a few ways but most don't work correctly, they end up reopening the old version.

It's going to sound crazy that WPF doesn't have a proper way to handle it (#fixwpf), but you'll need to reference System.Windows.Forms.dll and call System.Windows.Forms.Application.Restart();

A quick search found Rob Relyea's post about the same thing (XAML, WPF Microsoft Guy)http://robrelyea.wordpress.com/2007/07/24/application-restart-for-wpf/


It isn't necessary to include the winforms assembly just for this, that seems like overkill.

You can do the same thing that winforms does behind the scenes in it's restart method. After the Update Has been applied:

String ApplicationEntryPoint = ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName;Process.Start(ApplicationEntryPoint);//shutdown current instance here

This Will Start the New Version Of Your Application With the proper ClickOnce initialization.


        private static void RestartClickOnceApplication()        {            try            {                XDocument xDocument;                using (MemoryStream memoryStream = new MemoryStream(AppDomain.CurrentDomain.ActivationContext.DeploymentManifestBytes))                using (XmlTextReader xmlTextReader = new XmlTextReader(memoryStream))                {                    xDocument = XDocument.Load(xmlTextReader);                }                var description = xDocument.Root.Elements().Where(p => p.Name.LocalName == "description").First();                var publisher = description.Attributes().Where(a => a.Name.LocalName == "publisher").First();                var product = description.Attributes().Where(a => a.Name.LocalName == "product").First();                var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu) + @"\Programs\";                path += publisher.Value + @"\" + product.Value + ".appref-ms";                if (File.Exists(path))                {                    Process.Start(path);                    Application.Current.Shutdown();                }                else                {                    Application.Current.Shutdown();                }            }            catch            {                Application.Current.Shutdown();            }        }