What's equivalent in WPF for "Application.Restart()" in WindowsForms?Application.Curent object doesn't contain such method.<br>Any suggestions?<br><br>Thanks<br>© 2009 Microsoft Corporation. All rights reserved.Mon, 23 Nov 2009 12:39:58 Z0dca0561-d3e1-4f75-8675-28da404eefdehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#0dca0561-d3e1-4f75-8675-28da404eefdehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#0dca0561-d3e1-4f75-8675-28da404eefdeCyber Sinhhttp://social.msdn.microsoft.com/Profile/en-US/?user=Cyber%20SinhWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?Application.Curent object doesn't contain such method.<br>Any suggestions?<br><br>Thanks<br>Tue, 19 Sep 2006 12:56:31 Z2006-09-22T12:13:57Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#2343eb84-062e-4d1e-9450-89041a4dd744http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#2343eb84-062e-4d1e-9450-89041a4dd744Ashish Shetty - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Ashish%20Shetty%20-%20MSFTWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?Afaik, there isn't one in WPF.Tue, 19 Sep 2006 17:06:26 Z2006-09-22T12:13:57Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#6489b7db-45d1-44bf-927f-f1e222c722b5http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#6489b7db-45d1-44bf-927f-f1e222c722b5Cyber Sinhhttp://social.msdn.microsoft.com/Profile/en-US/?user=Cyber%20SinhWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?Why a such method has been omitted in WPF?<br>It's very useful for ClickOnce (after an update) or a language change...<br>There is absolutly no alternative?<br><br>Thanks<br><br>Tue, 19 Sep 2006 17:37:07 Z2006-09-19T17:37:07Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#3335ff53-f9c7-481e-a8cf-fe37ac9b9a11http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#3335ff53-f9c7-481e-a8cf-fe37ac9b9a11nickbaker77http://social.msdn.microsoft.com/Profile/en-US/?user=nickbaker77What's equivalent in WPF for "Application.Restart()" in WindowsForms?Is there going to be one? Or equivalent functionality? How are you supposed to 'refresh' the application following a ClickOnce update?<br><br>Thanks<br><br>Nick<br>Thu, 15 Mar 2007 16:10:06 Z2007-03-15T16:10:06Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#a5cb0865-3af6-45cc-bb11-5a061f13b76ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#a5cb0865-3af6-45cc-bb11-5a061f13b76eChango V. - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Chango%20V.%20-%20MSFTWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?This feature may be added later on, but Application.Restart() is not hard to implement for your application. Use Reflector to see the WinForms implementation. ;-)Fri, 16 Mar 2007 00:04:57 Z2007-03-16T00:04:57Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#2f9f90a2-f93e-4834-b0a9-bba36d92fcd2http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#2f9f90a2-f93e-4834-b0a9-bba36d92fcd2AlexVallathttp://social.msdn.microsoft.com/Profile/en-US/?user=AlexVallatWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?As it turns out, Application.Restart() is quite hard to implement properly, as evidenced by using Reflector to inspect the WinForms implementation and discovering that it isn't actually implemented properly there, for a start. It completely ignores command line escaping when creating the command line to start the new process with. To demonstrate this, you can use some very short code just to show command args and perform a restart:<br><br><font size=2><span style="font-family:Courier">        static void Main(string[] args)</span><br style="font-family:Courier"><span style="font-family:Courier">        {</span><br style="font-family:Courier"><span style="font-family:Courier">            Console.WriteLine(&quot;Restart Tester&quot;);</span><br style="font-family:Courier"><span style="font-family:Courier">            Console.WriteLine(&quot;command line: &quot; + Environment.CommandLine);</span><br style="font-family:Courier"><span style="font-family:Courier">            Console.WriteLine(&quot;args:&quot;);</span><br style="font-family:Courier"><span style="font-family:Courier">            foreach (string arg in args)</span><br style="font-family:Courier"><span style="font-family:Courier">                Console.WriteLine(&quot;\t&quot; + arg);</span><br style="font-family:Courier"><span style="font-family:Courier">            Console.WriteLine();</span><br style="font-family:Courier"><span style="font-family:Courier">            Console.WriteLine(&quot;Enter r to restart, or anything else to quit&quot;);</span><br style="font-family:Courier"><span style="font-family:Courier">            if(Console.ReadLine() == &quot;r&quot;)</span><br style="font-family:Courier"><span style="font-family:Courier">            {</span><br style="font-family:Courier"><span style="font-family:Courier">                Application.Restart();</span><br style="font-family:Courier"><span style="font-family:Courier">            }</span><br style="font-family:Courier"><span style="font-family:Courier">        }</span></font><br><br>Open up a command prompt, and run: <font size=2><span style="font-family:Courier">RestartTest.exe &quot;te\&quot; st&quot;<span style="font-family:Arial"> Due to the (admittedly obscure) command line escaping rules, the result of this is:<br><br><span style="font-family:Courier">command line: RestartTest.exe &quot;te\&quot; st&quot;</span><br style="font-family:Courier"><span style="font-family:Courier">args:</span><br style="font-family:Courier"><span style="font-family:Courier">        te&quot; st</span><br><br><span style="font-family:Arial">If the application is then restarted using Application Restart, the escaping is ignored, and the restarted instance displays:<br><br><span style="font-family:Courier">command line: &quot;C:\<span style="font-family:Arial">...</span>\RestartTest.exe&quot; &quot;te&quot; st&quot;</span><br style="font-family:Courier"><span style="font-family:Courier">args:</span><br style="font-family:Courier"><span style="font-family:Courier">        te</span><br style="font-family:Courier"><span style="font-family:Courier">        st</span><br style="font-family:Courier"><br>If you want to do Restart properly, it's substantially trickier to get the command line to pass to the next instance. My current code for doing this, which I hope handles all cases, is:<br><br><span style="font-family:Courier">        /// &lt;summary&gt;</span><br style="font-family:Courier"><span style="font-family:Courier">        /// Gets the command args this app was started with, as executed, not parsed into args[]</span><br style="font-family:Courier"><span style="font-family:Courier">        /// &lt;/summary&gt;</span><br style="font-family:Courier"><span style="font-family:Courier">        public static string GetCommandArgs()</span><br style="font-family:Courier"><span style="font-family:Courier">        {</span><br style="font-family:Courier"><span style="font-family:Courier">            string commandLine = Environment.CommandLine;</span><br style="font-family:Courier"><br style="font-family:Courier"><span style="font-family:Courier">            //Find either the space, which is a the delimeter, or a &quot; mark, which bounds spaces</span><br style="font-family:Courier"><span style="font-family:Courier">            int pos = 0;</span><br style="font-family:Courier"><span style="font-family:Courier">            do</span><br style="font-family:Courier"><span style="font-family:Courier">            {</span><br style="font-family:Courier"><span style="font-family:Courier">                if (pos &gt;= commandLine.Length)</span><br style="font-family:Courier"><span style="font-family:Courier">                    return String.Empty; //No command line args</span><br style="font-family:Courier"><br style="font-family:Courier"><span style="font-family:Courier">                pos = commandLine.IndexOfAny(new char[] { ' ', '&quot;' }, pos);</span><br style="font-family:Courier"><span style="font-family:Courier">                if (pos == -1)</span><br style="font-family:Courier"><span style="font-family:Courier">                    return String.Empty; //No command line args</span><br style="font-family:Courier"><br style="font-family:Courier"><span style="font-family:Courier">                if (commandLine[pos] == '&quot;')</span><br style="font-family:Courier"><span style="font-family:Courier">                {</span><br style="font-family:Courier"><span style="font-family:Courier">                    //Find the closing &quot; mark. &quot; marks can't be escaped in path names</span><br style="font-family:Courier"><span style="font-family:Courier">                    pos = commandLine.IndexOf('&quot;', pos + 1) + 1;</span><br style="font-family:Courier"><span style="font-family:Courier">                    if (pos == 0)</span><br style="font-family:Courier"><span style="font-family:Courier">                    {</span><br style="font-family:Courier"><span style="font-family:Courier">                        //No command line args. Probably malformed command line too.</span><br style="font-family:Courier"><span style="font-family:Courier">                        System.Diagnostics.Trace.TraceWarning(&quot;Could not find closing \&quot; mark in command line: &quot; + commandLine);</span><br style="font-family:Courier"><span style="font-family:Courier">                        return String.Empty;</span><br style="font-family:Courier"><span style="font-family:Courier">                    }</span><br style="font-family:Courier"><span style="font-family:Courier">                    //Otherwise, go round again to find another quote, or alternatively a space</span><br style="font-family:Courier"><span style="font-family:Courier">                }</span><br style="font-family:Courier"><span style="font-family:Courier">                else</span><br style="font-family:Courier"><span style="font-family:Courier">                {</span><br style="font-family:Courier"><span style="font-family:Courier">                    System.Diagnostics.Debug.Assert(commandLine[pos] == ' ', &quot;Expecting a space here, if not a \&quot; mark&quot;);</span><br style="font-family:Courier"><span style="font-family:Courier">                    //Everything past this point should now be the command args, as this is an unquoted space</span><br style="font-family:Courier"><span style="font-family:Courier">                    return commandLine.Substring(pos + 1);</span><br style="font-family:Courier"><span style="font-family:Courier">                }</span><br style="font-family:Courier"><span style="font-family:Courier">            } while (true);</span><br style="font-family:Courier"><span style="font-family:Courier">        }</span><br><br>I hope this helps, and if anyone has further refinements on the above, or notices cases for which it does not work, I'd be interested to hear them.<br><br>Alex<br></span></span></span></font>Tue, 06 Nov 2007 08:51:28 Z2007-11-06T08:51:28Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#b7ed0814-1063-45de-a5e8-1f4d1e77be5dhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#b7ed0814-1063-45de-a5e8-1f4d1e77be5dJunior Mayhehttp://social.msdn.microsoft.com/Profile/en-US/?user=Junior%20MayheWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?As far as I know you could add a reference to System.Windows.Forms and add these code statements: <div><br/></div> <div> <div><br/></div> <div> <pre lang="x-c#">System.Windows.Forms.Application.Restart(); Application.Current.Shutdown();</pre> <br/></div> </div>Thu, 23 Jul 2009 18:50:04 Z2009-07-23T18:50:04Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#6d6e390a-cc00-443f-b05a-c7ba2c42ab9bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0dca0561-d3e1-4f75-8675-28da404eefde#6d6e390a-cc00-443f-b05a-c7ba2c42ab9bMichael Synchttp://social.msdn.microsoft.com/Profile/en-US/?user=Michael%20SyncWhat's equivalent in WPF for "Application.Restart()" in WindowsForms?<span style="font-size: x-small;"><font size="2"> <p>IMO, We should never reference to WIndows.Form. <br /><br />Better to use the code&nbsp;like that below&nbsp;.... <br /><br />System.Diagnostics.</p> </font></span> <p><span style="font-size: x-small; color: #2b91af;"><span style="font-size: x-small; color: #2b91af;">Process</span></span><span style="font-size: x-small;">.Start(</span><span style="font-size: x-small; color: #2b91af;"><span style="font-size: x-small; color: #2b91af;">Application</span></span><span style="font-size: x-small;">.ResourceAssembly.Location);<br /></span><span style="font-size: x-small; color: #2b91af;"><span style="font-size: x-small; color: #2b91af;">Application</span></span><span style="font-size: x-small;">.Current.Shutdown();</span></p><hr class="sig">Michael Sync: blog: http://michaelsync.netFri, 02 Oct 2009 10:17:37 Z2009-10-02T10:17:37Z