12/03/13

WPF restart application


I have tried below code after submitting the data but application gets crashed while restarting the application.

            if (Restart (Condition))
            {
                System.Windows.Application.Current.Shutdown();
                
                Process MyProcess = new Process();
                MyProcess.StartInfo.FileName = Application.ResourceAssembly.Location;
                MyProcess.Start();

                return;
            }

To avoid multiple instance application should ensure that the new instance is started as late as possible in the shutdown-process to prevent problems with single-instance-apps.

Application.Current.Exit += new ExitEventHandler(Current_Exit);
Application.Current.Shutdown();

  void Current_Exit(object sender, ExitEventArgs e)
  {
      Process.Start(Application.ResourceAssembly.Location);
  }

No comments:

Post a Comment