Problem with Environment.CommandLine routine.
Posted on 2006-07-13
I have an app that is controlled by a module to make sure it is only opened once. Now that works fine but the problem is if my app is open, and a command argument, Environment.CommandLine, is sent to it, nothing happens. The code below just shows the Module to open my app.
(Thanks to Yzlat for the following code)
Dim bAppOwnership As Boolean = False
Dim sAppName As String = "Local\" & Reflection.Assembly.GetExecutingAssembly.GetName.Name
'Return value - contains true if the calling thread was granted initial ownership of the mutex.
Dim bAppFirstInstance As Boolean
'Static ensures the mutex is not garbage collected until the application is unloaded
Static m As System.Threading.Mutex
m = New Threading.Mutex(bAppOwnership, sAppName, bAppFirstInstance)
'If this is the first instance of the mutex, then run the application
If bAppFirstInstance Then Application.Run(New frmConfig)
Catch ex As Exception
'error - display a system modal error message box
MsgBox(ex.Message, Microsoft.VisualBasic.MsgBoxStyle.SystemModal Or Microsoft.VisualBasic.MsgBoxStyle.Critical Or Microsoft.VisualBasic.MsgBoxStyle.OKOnly, _
Application.ProductName & " Is Unable To Start. ")
m = Nothing