Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart application using C#

Tags:

c#

wpf

How can I restart my WPF application using C#?

like image 870
kartal Avatar asked Oct 09 '10 00:10

kartal


People also ask

How to restart program with if in C?

You can simply use a do ... while loop (including your program source code). do { /* Get user input. */ } while (a <= 0);

How to reset function in C?

ANSWER. You may typecast the address of the reset vector (0x0000) to a function pointer and call that from C using the following: ((void (code *) (void)) 0x0000) (); For example, the following program continuously resets itself.


2 Answers

I don't think there's a direct method in WPF like there is in WinForms. However, you could use methods from the Windowns.Form namespace like this: (You might need to add a reference to the System.Windows.Form assembly)

System.Windows.Forms.Application.Restart();  System.Windows.Application.Current.Shutdown(); 
like image 155
keyboardP Avatar answered Oct 14 '22 05:10

keyboardP


The following is the best solution I found, you don't need to add a reference to System.Windows.Forms, instead you need add the namespace System.Diagnostics which you already has a reference to its assembly:

Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); 
like image 44
Mohammed A. Fadil Avatar answered Oct 14 '22 07:10

Mohammed A. Fadil