Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a second instance of a WPF application from within the first

If our standalone app were just a downloaded .exe file (i.e. deployed using windows installer), it would be fairly simple to have a running instance launch a second instance using System.Diagnostics.Process.Start. Unfortunately, our WPF application is deployed VIA ClickOnce, so there's no local file system path to it as far as I know.

How can I launch a second instance of a running ClickOnce app? (And pass it command line parameters if possible.)

like image 424
Alain Avatar asked Aug 02 '12 14:08

Alain


People also ask

How do I open a second window in WPF?

You will need to create an instance of a new window like so. var window2 = new Window2(); Once you have the instance you can use the Show() or ShowDialog() method depending on what you want to do.

What is the difference between page and window in WPF?

Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.

Where does the execution start in a WPF application?

Entry point is App. xaml.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.


2 Answers

You're incorrect: there is a local path, under your local Application Data folder. Alternatively, you can relaunch the application using the Uri. In short, you should be able to work out the launch path for your application (maybe using Environment.CommandLine or System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) as you would for a regular application, and use that.

like image 113
Dan Puzey Avatar answered Sep 28 '22 05:09

Dan Puzey


well, there IS a local filesystem path when you deploy it via clickonce. Try

yourWindow.GetType().Assembly.Location

-> this will give you the full path to your assembly.

like image 21
Joachim Kerschbaumer Avatar answered Sep 28 '22 07:09

Joachim Kerschbaumer