Hack Forums
[.NET] Mutex - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Mutex (/showthread.php?tid=584046)



Mutex - jojogizmojake - Aug 2, 2010

Here is a simple mutex that I coded pretty self explanatory

Declare:
Code
Private check As Mutex

Sub:
Code
Private Sub checkifopen(ByVal mute As String)
  Try
    System.Threading.Mutex.OpenExisting(mute)
    Me.Close()
  Catch ex As Exception
    check = New System.Threading.Mutex(False, mute)
    Exit Sub
  End Try
End Sub

How to Use:
Code
checkifopen("Mutex Here")



* - wargod97 - Aug 2, 2010

sorry for the noob question but what is a mutex :$?


* - grimd34th - Aug 2, 2010

sub is screwed up

Code
Private Sub checkifopen(ByVal mute As String)
  Try
    System.Threading.Mutex.OpenExisting(mute)
    Me.Close()
  Catch ex As Exception
    check = New System.Threading.Mutex(False, mute)
  End Try
    End Sub
fixed

also it would be better if you
Code
Private check As Mutex
Private Sub checkifopen(ByVal mute As String)
  Try
    Messagebox.Show(System.Threading.Mutex.OpenExisting(mute))
    Catch ex As Exception
  check = New System.Threading.Mutex(False, mute)
  messagebox.show(ex.message)
  End Try
End Sub



* - jojogizmojake - Aug 2, 2010

(Aug 2, 2010 10:22 AM)grimd34th Wrote:  sub is screwed up

Code
Private Sub checkifopen(ByVal mute As String)
  Try
    System.Threading.Mutex.OpenExisting(mute)
    Me.Close()
  Catch ex As Exception
    check = New System.Threading.Mutex(False, mute)
  End Try
    End Sub
fixed

also it would be better if you
Code
Private check As Mutex
Private Sub checkifopen(ByVal mute As String)
  Try
    Messagebox.Show(System.Threading.Mutex.OpenExisting(mute))
    Catch ex As Exception
  check = New System.Threading.Mutex(False, mute)
  messagebox.show(ex.message)
  End Try
End Sub

I didnt put message boxes because i didnt want the user to see anything. Oh and you removed exit sub, but it still works with it.