Results 1 to 2 of 2

Thread: Mutex Ownership in Release and Debug Builds.[Resolved]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    Mutex Ownership in Release and Debug Builds.[Resolved]

    Here is the code:
    VB Code:
    1. Imports System.Reflection
    2. Imports System.Runtime.InteropServices
    3. Imports System.Threading
    4.  
    5. Sub Main()
    6.         Dim gd As GuidAttribute
    7.         gd = GuidAttribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(GuidAttribute))
    8.         Dim guidstring As String = gd.Value.ToString
    9.         Dim mymutex As Mutex
    10.         Dim isrunning As Boolean
    11.         mymutex = New Mutex(True, guidstring, isrunning)
    12.         MessageBox.Show(isrunning) 'Its here now just to see the value and will be removed in original.
    13.         If Not isrunning Then
    14.              Exit Sub
    15.         End If
    16. '
    17. '
    18. 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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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
  •  



Click Here to Expand Forum to Full Width