-7

I'm developing a media player and unlike other applications when i click and open with the application, it creates a new instance. how can i prevent it from doing that and actually play the song with the same application running.

Thanks

  • 7
    What have you tried? Show us how you are trying to do it now in code. Lots of information on this out there already. – Evan L Jan 16 '14 at 21:00
  • 1
    It's heaps of information about this in the internet. Please don't be lazy and check google first. – zerkms Jan 16 '14 at 21:00
  • Did you try a search? http://stackoverflow.com/questions/93989/prevent-multiple-instances-of-a-given-app-in-net – timbck2 Jan 16 '14 at 21:01
  • Welcome to Stack Overflow. Show your code please. If it's not running look it over. If you still don't understand feel free to post the question here with the code. – puretppc Jan 16 '14 at 21:01
  • 2
    @zerkms funniest thing is, it takes more effort to open a SO account, type in a bad question and post it than it ever would to Google something like this... craziness ;) – Evan L Jan 16 '14 at 21:01
  • 1
    @Evan L: what is even funnier - is that a person who develops a "media player" asks such a question. "I'm building a rocket, where can I buy a screw driver" – zerkms Jan 16 '14 at 21:04
  • @zerkms HA! No doubt I didn't even look at that aspect. Thanks for the laugh ;) – Evan L Jan 16 '14 at 21:05
  • @zerkms, to be fair - using media APIs is child's play and anyone can write their own media player with a minimal of effort. That said, your point stands well. "I've managed to write a program that parses DNA sequences and can predict within a 99% percentile the chances of someone getting cancer, the program can also predict the best treatment to kill the tumour at an early stage in development. Can someone help me export this data to a CSV file? Please, I've tried everything." – Moo-Juice Jan 16 '14 at 21:11

1 Answers1

1

I use this approach for this first part of your question. Just add this code to a initialization code of your project

bool b = true;
Mutex mutex = new Mutex(true, Application.ProductName, out b);
if (!b) throw new InvalidOperationException("already running");

The second part needs some sort of interprocess communication(such as NamedPipes) which is too broad to answer in a single answer.

Community
  • 1
  • 1
L.B
  • 114,136
  • 19
  • 178
  • 224