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 ??
thorv71Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
thorv71Author Commented:
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.ApplicationServices

Public Class MyApplication

    Public Sub Me_StartupNextInstance(ByVal sender As Object, ByVal e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance

        Dim test As String = ""

        If e.CommandLine.Count > 0 Then
            Test = e.CommandLine.Item(0).ToString()
            MessageBox.Show(test)
        End If

    End Sub

    ' Declaration
    Public Event StartupNextInstance(ByVal sender As Object, ByVal e As StartupNextInstanceEventArgs)

End Class
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Éric MoreauSenior .Net ConsultantCommented:
If I remember correctly, this has to be tested outside Visual Studio (both instance). Is this how you try to test it?
0
thorv71Author Commented:
Yes, I build the exe file and started it from a shourtcut on desktop serveral times.
And nothing happens the second time.
0
thorv71Author Commented:
Her is the shortcut: "D:\VB.NET\Kalkulasjon\bin\Debug\Kalkulasjon.exe" testvar
0
Éric MoreauSenior .Net ConsultantCommented:
add a messagebox at the beginning of your event to see what is received
0
thorv71Author Commented:
I have tried that already and nothing happens :-(

It's looks like the application don't load ApplicationEvents at startup ever.
0
thorv71Author Commented:
Is it possible that the class or public name has to be another name ?
0
Éric MoreauSenior .Net ConsultantCommented:
download my demo code and try it.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
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".
0
thorv71Author Commented:
When i set the Left Dropdown to "MyApplication Event", I only get the (Declarations) in the right dropdown :-(
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You have to re-enable the “Enable application framework” option...
0
thorv71Author Commented:
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.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0
thorv71Author Commented:
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 :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.