473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mutex clarification and code

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
Nov 20 '05 #1
4 1376
* "=?Utf-8?B?amNyb3VzZQ==?=" <an*******@discussions.microsoft.com> scripsit:
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').

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
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
Nov 20 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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()
End If

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 Sub
Thanks,
John

Nov 20 '05 #4
* "=?Utf-8?B?amNyb3VzZQ==?=" <an*******@discussions.microsoft.com> scripsit:
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
///
End Sub


--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
1
by: Lloyd Dupont | last post by:
I have some code where I updatde a file (that might not exist yet). In fact this file contains 2 integers and is used in only one function. I thought overkill to configure, deploy and maintain a...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
1
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work...
11
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce...
2
by: tshad | last post by:
I am running a program as a Windows service which works fine. I am using a Mutex to prevent multiple threads from from accessing my log text file at the same time. It works fine in the Service:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.