|
-
Apr 18th, 2003, 07:25 AM
#1
Thread Starter
Frenzied Member
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?
Last edited by Lunatic3; Apr 18th, 2003 at 07:58 AM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 18th, 2003, 07:58 AM
#2
Thread Starter
Frenzied Member
Ok, I found the where the problem lies.
I shouldn't have declared the variable mymutex locally.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|