1

I have it set so if you open a file, it launches my application and adds it to the start-up arguments. But how can I make it so if I double click on a file it loads it in the application that's already running? Rather than loading each file into it's own instance of the application.

Ria
  • 10,237
  • 3
  • 33
  • 60
Alexander Forbes-Reed
  • 2,823
  • 4
  • 27
  • 44
  • http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application http://elegantcode.com/2011/03/02/wpf-advanced-jump-lists-using-a-single-instance-application/ http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx http://blogs.microsoft.co.il/blogs/maxim/archive/2010/02/13/single-instance-application-manager.aspx The above links describe how you can build single instance application – Ehsan Aleem Avee Oct 09 '12 at 05:22
  • My application was WPF (I should of mentioned that, sorry everyone else), so the second solution worked perfectly! Thank you very much. – Alexander Forbes-Reed Oct 09 '12 at 06:15

3 Answers3

2

Mutex is want you need to have a single instance of the application.

bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}

You can refer this LINK for detailed information.

Shiridish
  • 4,942
  • 5
  • 33
  • 64
0

use mdiParent and child forms in C# I think it's great feature of vs C#


for more inforamtion: http://msdn.microsoft.com/en-us/library/d4dabts7%28v=vs.80%29.aspx

0

You need to make your application single-Instance, see this article:

Ria
  • 10,237
  • 3
  • 33
  • 60