I'm developing a small tools to receive command line argument. Argument is send during runtime. I found from this article :
- Is there a way or event to retrieve command line arguments on runtime
- Pass Command Line to first instance of a Single Instance App
and try to implemented using startupnextinstance events
my code is like this on ApplicationEvents
Partial Friend Class MyApplication
Private Sub MyApplication_StartupNextInstance(sender As Object, e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
Dim f = Application.MainForm
If f.GetType Is GetType(Form1) Then
CType(f, Form1).NewArgumentsReceived(e.CommandLine.ToArray)
End If
End Sub
End Class
and in form1, I'm using this code:
Public Class Form1
Dim strFile As String = "d:\temp.txt"
Dim fileExists As Boolean = File.Exists(strFile)
Public Sub NewArgumentsReceived(args As String())
If args.Length > 0 Then
Using sw As New StreamWriter(strFile)
sw.WriteLine(args(0), Environment.NewLine)
sw.Flush()
End Using
End If
End Sub
End Class
I'm trying to send output to file (just for debugging). When I'm try to run this application, I can't receive the argument that send to this tools (temp file is empty) also my tools in not run in single instance again
My purpose is read command line argument that send at runtime and can read at every where form.
Any wrong with my code? Why single instance application is not working in here?