Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"make single instance application" what does this do?

in vb 2008 express this option is available under application properties. does anyone know what is its function? does it make it so that it's impossible to open two instances at the same time?

like image 695
Alex Gordon Avatar asked Aug 25 '09 14:08

Alex Gordon


People also ask

How to create a single instance application in VB NET?

Simply add this module to your VB.NET app, change the project start-up object to Main () and you have a single instance application. Sometimes you want your application to run single instance.

How many process instances can a single application instance host?

A single application instance may host multiple process instances. During the lifetime of an application instance, many process instances may be enacted and terminated. A tenant can request modifications to the SaaS service to suit their changed business objectives.

Is it possible to open a single instance of an application?

With some firewalls, it's impossible to open even one instance - your application crashes at startup! See this excellent article by Bill McCarthy for more details, and a technique for restricting your application to one instance.

What is the difference between single-instanced apps and multi-instances?

Single-instanced apps only allow one instance of the app running at a time. WinUI apps are multi-instanced by default. They allow you to launch multiple instances of the same app at one time, which we call multiple instances.


2 Answers

Why not just use a Mutex? This is what MS suggests and I have used it for many-a-years with no issues.

Public Class Form1
Private objMutex As System.Threading.Mutex
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'Check to prevent running twice
    objMutex = New System.Threading.Mutex(False, "MyApplicationName")
    If objMutex.WaitOne(0, False) = False Then
        objMutex.Close()
        objMutex = Nothing
        MessageBox.Show("Another instance is already running!")
        End
    End If
    'If you get to this point it's frist instance

End Sub
End Class

When the form, in this case, closes, the mutex is released and you can open another. This works even if you app crashes.

like image 100
Steve Avatar answered Jan 03 '23 20:01

Steve


does it make it so that it's impossible to open two instances at the same time?

Yes.

like image 31
sepp2k Avatar answered Jan 03 '23 18:01

sepp2k