Single instance app

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Is there a way to ensure that an app is only run once and if it is run twice
it terminates?

Thanks

Regards
 
Hi

Thanks for that. I need to quit the app as soon as it starts but
Application.Quit is not available in
Sub MyApplication_StartupNextInstance event. What can I do to quit the app
as soon as it starts the second time?

Thanks for your help.

Regards
 
There is no need for Application.Quit. The .NET Runtime will take care of
that once you have checked the Make Single Instance Application. You can
even bring the previous instance to front using "e.BringToForeground = True"
in the same event handler.

Regards,
Shuja
 
That is only applicable if you have the "Enable Visual Styles"
checkbox on. I don't know about you, but I prefer to configure VB.NET
apps the same way C#.NET does by default, and have the startup object
as SubMain, enable visual styles there manually and open the main form
with an Application.Run call.

You could use 'System.Threading.Mutex' to prevent multiple instances:

FAQ for the microsoft.public.languages.csharp newsgroup
<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>
 
That is only applicable if you have the "Enable Visual Styles"
checkbox on.

Are you sure about that? I thought it was available if you've chosen to
"Enable Application Frameworks".
 
Scott M. said:
Are you sure about that? I thought it was available if you've chosen to
"Enable Application Frameworks".

C# doesn't support the application framework.
 
Back
Top