mutex clarification and code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have searched this board for an example and also read Cor's link to the Google thread. I have an application with a startup module called mStartup. My application, after compiled is called CPViewer.exe Here is the code from the Sub Main:

Dim owned As Boolea
Dim mut As New System.Threading.Mutex(True, "CPViewer.exe", owned
Sub main(

If owned The
Application.Run(New frmVertical
mut.ReleaseMutex(
Els
Application.Exit(
End I

End Su

I believe the code is correct, however, what do i need to put in place of the "Application.Exit()" to get the second instance to stop immediately and clean up after itself? As it is now, I continues execution of the code after reading the line. "Application Exit()" seems to work the way I want if it's in a form but not in a module. If I ut "End" in place of "Application Exit()" it stops but I gather from reading here that that's not the proper way to do things

Thanks
John
 
* "=?Utf-8?B?amNyb3VzZQ==?= said:
I have searched this board for an example and also read Cor's link to the Google thread. I have an application with a startup module called mStartup. My application, after compiled is called CPViewer.exe Here is the code from the Sub Main:

Dim owned As Boolean
Dim mut As New System.Threading.Mutex(True, "CPViewer.exe", owned)
Sub main()

If owned Then
Application.Run(New frmVertical)
mut.ReleaseMutex()
Else
Application.Exit()
End If

End Sub

I believe the code is correct, however, what do i need to put in place
of the "Application.Exit()" to get the second instance to stop
immediately and clean up after itself? As it is now, I continues
execution of the code after reading the line. "Application Exit()" seems
to work the way I want if it's in a form but not in a module. If I ut
"End" in place of "Application Exit()" it stops but I gather from
reading here that that's not the proper way to do thin

Just don't execute /anything/, then the application will quit (which
means, that you only need to remove the 'Else' part of the 'If...End
If').
 
The problem is that it executes the rest of the code in the Sub Main and i want it to exit immediately. Here is the entire Sub Main

Sub main(

If owned The
Application.Run(New frmVertical
mut.ReleaseMutex(
End I

strMyStartupArguments = System.Environment.GetCommandLineArg

If strMyStartupArguments.Length = "2" The
strRomName = (strMyStartupArguments(1).ToString
strParentName = (strMyStartupArguments(1).ToString
strLookup = strRomNam
End I

If strMyStartupArguments.Length = "4" The
strRomName = (strMyStartupArguments(1).ToString
strParentName = (strMyStartupArguments(3).ToString
strLookup = strRomNam
End I

strLookup = "name " & LCase(strLookup

D
strLine = sr.ReadLine(
intCheck = InStr(strLine, strLookup
Loop Until intCheck >

D
strLine = sr.ReadLine(
intCheck = InStr(strLine, "description"
Loop Until intCheck >

strlength1 = Len(strLine
strGameName = Microsoft.VisualBasic.Right(strLine, strlength1 - 14

strlength2 = Len(strGameName
strGameName = Microsoft.VisualBasic.Left(strGameName, strlength2 - 1

D
strLine = sr.ReadLine(
intCheck = InStr(strLine, "video ( screen"
Loop Until intCheck >
sr.Close(

If strLine.IndexOf("vertical") > 0 The
frmV.ShowDialog(
ElseIf strLine.IndexOf("horizontal") > 0 The
frmH.ShowDialog(
End I

End Su

Thanks
John
 
How about moving the rest of the code after mut.ReleaseMutex()

If owned Then
Application.Run(New frmVertical)
mut.ReleaseMutex()

' Deal with the command line arguments here
End If

jcrouse said:
The problem is that it executes the rest of the code in the Sub Main and i
want it to exit immediately. Here is the entire Sub Main.
 
* "=?Utf-8?B?amNyb3VzZQ==?= said:
The problem is that it executes the rest of the code in the Sub Main and i want it to exit immediately. Here is the entire Sub Main.

Sub main()

If owned Then
Application.Run(New frmVertical)
mut.ReleaseMutex()

Remove the 'Else If' like here.
strMyStartupArguments = System.Environment.GetCommandLineArgs

If strMyStartupArguments.Length = "2" Then
strRomName = (strMyStartupArguments(1).ToString)
strParentName = (strMyStartupArguments(1).ToString)
strLookup = strRomName
End If

If strMyStartupArguments.Length = "4" Then
strRomName = (strMyStartupArguments(1).ToString)
strParentName = (strMyStartupArguments(3).ToString)
strLookup = strRomName
End If

strLookup = "name " & LCase(strLookup)

Do
strLine = sr.ReadLine()
intCheck = InStr(strLine, strLookup)
Loop Until intCheck > 0

Do
strLine = sr.ReadLine()
intCheck = InStr(strLine, "description")
Loop Until intCheck > 0

strlength1 = Len(strLine)
strGameName = Microsoft.VisualBasic.Right(strLine, strlength1 - 14)

strlength2 = Len(strGameName)
strGameName = Microsoft.VisualBasic.Left(strGameName, strlength2 - 1)

Do
strLine = sr.ReadLine()
intCheck = InStr(strLine, "video ( screen")
Loop Until intCheck > 0
sr.Close()

If strLine.IndexOf("vertical") > 0 Then
frmV.ShowDialog()
ElseIf strLine.IndexOf("horizontal") > 0 Then
frmH.ShowDialog()
End If

\\\
End If
///
 
Back
Top