thorv71
asked on
How to check and use an already open vb.net application from vb.net with parameters
I'm building an application where I now get parameters like "myfile.exe" /test.
This works when i get the parameters in the load section in start form, but the problem accurs when the application already is open, because when I then try to use "myfile.exe" /test from the another application, the "myfile.exe" starts a new instance, and I need then to use the existing instance and still make it posible to send and receive new parameters between the application. How to do this ??
This works when i get the parameters in the load section in start form, but the problem accurs when the application already is open, because when I then try to use "myfile.exe" /test from the another application, the "myfile.exe" starts a new instance, and I need then to use the existing instance and still make it posible to send and receive new parameters between the application. How to do this ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I now tried to use "Single instance application"
and the StartupNextInstance in ApplicationEvents, but nothing happens when I try to start the application the second time :-(
Her is the code:
Imports System.Globalization
Imports Microsoft.VisualBasic.Appl icationSer vices
Public Class MyApplication
Public Sub Me_StartupNextInstance(ByV al sender As Object, ByVal e As StartupNextInstanceEventAr gs) Handles Me.StartupNextInstance
Dim test As String = ""
If e.CommandLine.Count > 0 Then
Test = e.CommandLine.Item(0).ToSt ring()
MessageBox.Show(test)
End If
End Sub
' Declaration
Public Event StartupNextInstance(ByVal sender As Object, ByVal e As StartupNextInstanceEventAr gs)
End Class
and the StartupNextInstance in ApplicationEvents, but nothing happens when I try to start the application the second time :-(
Her is the code:
Imports System.Globalization
Imports Microsoft.VisualBasic.Appl
Public Class MyApplication
Public Sub Me_StartupNextInstance(ByV
Dim test As String = ""
If e.CommandLine.Count > 0 Then
Test = e.CommandLine.Item(0).ToSt
MessageBox.Show(test)
End If
End Sub
' Declaration
Public Event StartupNextInstance(ByVal sender As Object, ByVal e As StartupNextInstanceEventAr
End Class
If I remember correctly, this has to be tested outside Visual Studio (both instance). Is this how you try to test it?
ASKER
Yes, I build the exe file and started it from a shourtcut on desktop serveral times.
And nothing happens the second time.
And nothing happens the second time.
ASKER
Her is the shortcut: "D:\VB.NET\Kalkulasjon\bin \Debug\Kal kulasjon.e xe" testvar
add a messagebox at the beginning of your event to see what is received
ASKER
I have tried that already and nothing happens :-(
It's looks like the application don't load ApplicationEvents at startup ever.
It's looks like the application don't load ApplicationEvents at startup ever.
ASKER
Is it possible that the class or public name has to be another name ?
download my demo code and try it.
Instead of writing your own class, use the one that is provided for you.
Go to Project --> Properties.
In the bottom right of the default Tab, click the "View Application Events" button.
Then across the top, change the LEFT dropdown to "(MyApplication Events)", and the RIGHT to "StartupUpNextInstance".
Go to Project --> Properties.
In the bottom right of the default Tab, click the "View Application Events" button.
Then across the top, change the LEFT dropdown to "(MyApplication Events)", and the RIGHT to "StartupUpNextInstance".
ASKER
When i set the Left Dropdown to "MyApplication Event", I only get the (Declarations) in the right dropdown :-(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks !!!!! :-)
Now it works, but I also had to delete ApplicationEvents.vb file before I enabled the Framework again, then when I enabled the framework it generatet a new file.
Now it works, but I also had to delete ApplicationEvents.vb file before I enabled the Framework again, then when I enabled the framework it generatet a new file.
Right...sometimes you might want to create your own implementation as emoreau suggested. Just depends what you're doing. In many cases, though, you just need the built-in one.
ASKER
Thanks very much to you both!
Emoreau got me on the right road using "Single instance application" and StartupNextInstance, and Idle_Mind fixed the last annoying error for me :-)
Emoreau got me on the right road using "Single instance application" and StartupNextInstance, and Idle_Mind fixed the last annoying error for me :-)
https://www.experts-exchange.com/questions/26819949/How-to-comunicate-from-process-and-main-program-vb-net.html