How to transfer control to the new instance in a single instance application
I have a single instance VB 2010 application I know how to communicate with the next instances run through the StartupNextInstance application event. The usual way of working with this is parsing command line arguments of the new instance and continue execution of the old instance.
What I would like to do is replace the running instance with the new one. Is there any way to do this开发者_开发知识库 other than disabling the single instance property ?
Define the mutex for your app
Public objMutex As Mutex
Public mutexID As String = "SINGLE_INSTANCE_APP_MUTEX_YOUR_APP"
Then check if it is running or not.
objMutex = New Mutex(False, mutexID)
If objMutex.WaitOne(0, False) = False Then
' If we get here we where already running
Process.GetProcessById(oldInstancePID).Kill()
EndIf
精彩评论