Salve! I want to exit my GUI application (vb.net 4) using a commandline parameter. I should send this from the commandline:
myapplication.exe quit
-and an already running instance of the application should exit.
Now, I have a mutex detection in place so that I can only have one instance of the application running at a time. It seems that if I send a commandline, it won’t work on an already running application; it will only work on one that is launching.
Easy Send Message to Running Instance of Application
Hello, everyone! After finding this nice post here, looking for a way that a single application would do one thing with the first instance, but the second instance would cause the first instance do something else.
The value of this is that you can (with your own, additional programming) use this to achieve the effect of sending commandline parameters to a running application. You would actually use a second instance of the app to send the commandline parameters as messages to the first instance. It works okay on my Windows XP, but I’m rather new to vb.net, so if you’ve any improvements, I’d like to know!
So I adapted anoriginalidea’s nice example and below is my result. This is the bare-bones of it all, so you just see here the essentials of the process.
It works like this:
really Bob!” to let you know that the function fired off.
then app1 will exit becuase app2 told it to exit when InterComClient()
was called.
first add this as your sub main
the mutex will check to see if your application is already running or not.
Now Add this in a module in your application
[update]
Just FYI for anyone, I’ve used this in my application now for awhile, and it seems to work very well.