Mutex Ownership in Release and Debug Builds.[Resolved]
Here is the code:
VB Code:
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Threading
Sub Main()
Dim gd As GuidAttribute
gd = GuidAttribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(GuidAttribute))
Dim guidstring As String = gd.Value.ToString
Dim mymutex As Mutex
Dim isrunning As Boolean
mymutex = New Mutex(True, guidstring, isrunning)
MessageBox.Show(isrunning) 'Its here now just to see the value and will be removed in original.
If Not isrunning Then
Exit Sub
End If
'
'
End Sub
I use this code to create a named (tried to be a unique name, thus used assembly GUID info) mutex and gave the calling thread its ownership. Then trying another instance of the program cant take the ownership of this mutex and so 'isrunning' returns False. So If isrunning is false I can safely exit this application instance.
But the problem is that it works if i build the application under Debug mode and in Release mode any instance will take the ownership and isrunning will be alwyas True. What can I do about it?