Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Instance of an application

Tags:

c#

.net

wpf

I've made MP3 Files on my computer to associate with my media player. So when i double click a MP3 file in the explorer, obviously the media player fires up and plays it.

My problem I can prevent multiple instances popping up, but how can i transfer the file path of the new instance to the instance i am using already

What i want to happen: I double click a song,... and im listening to it I double click another song and the current song should stop and new song should start playback, without popping up a new instance of the application.

I use Mutex to check whether there is already a running instance. To get file path i use Environment.GetCommandLineArgs()

All I need is to pass the file's path to the current instance. How can I do this??

like image 734
Sylens Avatar asked Nov 13 '12 13:11

Sylens


People also ask

What is an instance of an application?

An application instance is a collection of services and service groups that is associated with a top-level consumer. Start by creating an application instance from an application template. Then, deploy the application instance and any packages associated with it.

What is an instance in Web application?

An instance is a single copy of the software running on a single physical or virtual server. If you run two copies of the software on the same physical or virtual server, that counts as two instances.

What is application instance in Java?

Within a single installed application server instance you can offer companies or individuals domain names, IP Addresses, and some administration capabilities. For the users, it is almost as if they have their own web server, without the hardware and basic server maintenance.


2 Answers

Essentially you will have to build this into your application.

When a user clicks a second song, you would have to have some way for the current instance to kill the previous instance of your application or send it a message.

These seems a little dirty to me.

I think a clean approach would be to write a small app_booter.exe that is associated with your media files. When a media file is clicked, it starts this _app_booter_ which :

  1. Looks for a running instance of your application.
  2. Send data to it to stop the current song and play this new one.
  3. If the app is not running, it just starts it with the song on the command line.

To send your application data from this other exe you could take a look at IPC: Interprocess communication for Windows in C# (.NET 2.0)

I think the WM_COPYDATA approach mentioned in the above post, or a tcp socket would suffice since your data is pretty simple, just a file path and maybe a command.

I think keeping two separate exes will be easier and cleaner than building your app to talk to its previous instance.

like image 142
gideon Avatar answered Oct 29 '22 16:10

gideon


I think you are looking for this http://wpfinstanceawareapp.codeplex.com/

Provides the functionality for a single instance application that can pass the command line arguments to the first instance.

like image 33
Bob Vale Avatar answered Oct 29 '22 16:10

Bob Vale