1

I need to restart application after I click in button. Problem is that I have some data saved in Application.Current.Properties. So what I need to do is:

Application.Current.Shutdown();

then start window as Mywindow mw = new Mywindow(parameters);

At this momment aftrer I raise Shutdown(), it just closing app and cant start window.

Is there any way to do it?

nathanchere
  • 8,008
  • 15
  • 65
  • 86
user13657
  • 745
  • 3
  • 17
  • 36

2 Answers2

0

No, you can't instruct a process to restart itself.

You'll need to execute a second process that stops the first, then starts it again.

Something along the lines of:

// stop
Process[] procs = Process.GetProcessesByName("process.exe");
foreach (Process p in procs) { p.Kill(); }

// start
Process.Start(@"c:\pathToProcess\process.exe -openConfig");
paul
  • 21,653
  • 1
  • 53
  • 54
  • Thanks for fast answer. Any sample code? By the way, I have login window and another window with configuration (in configuration window I need to restart app) so is it possible to stop first process, then run another with configuration window open? – user13657 Sep 16 '13 at 13:33
  • well, that I do like System.Windows.Forms.Application.Restart(); But as I said i need to open configurationWindow ;) – user13657 Sep 16 '13 at 13:42
0

Yes you can.

1-first we need to open a new instance of the program before Exit the current one

2-exit the current program

so your code will be like this:

  System.Windows.Forms.Application.Restart();

     Application.Current.Shutdown();
Sulyman
  • 440
  • 5
  • 14