Link to home
Start Free TrialLog in
Avatar of PNRT
PNRT

asked on

VB.Net Passing command line parameters to single instance app

Hi Experts
I have a system that calls my app from the command line with differing parameters each time.  I need to be able to start my app on the first call and thereafter just receive the different parameters on each subsequent call but also to remain open all the time.   The system may call my app anywhere from 1to 5 times a second passing new parameters so the process will need to be quite fast.   I have seen many different examples on the net but all seem overly complicated and most have the first instance of the app closing when the second call starts.   Any help would be appreciated.   Many Thanks.
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

You did not chose the right configuration for what you want to do.

Command line arguments have but one role: pass startup parameters.

If the system need to communication continuously with your application, then you need to have your application waiting to receive the calls. This means building your application as a service or as a dll, and have your system call it as such.
Avatar of SStory
Without knowing what you are trying to do it is difficult to answer. However, my guess is that you'd want two processes (one a server process--and possibly running as a service depending upon what it does). Then the app people call is just a communicator that gets the parameters from the command-line and uses some form of Inter Process Communication to send that information to the other process or service.

Some thoughts on how to do this:
1.)
app1 param1 param2 ,etc writes a file to a decided upon location (app specific folder with a name no one else would uses) with an extension that of whatever type. Then when it is ready for the info to be consumed by the second app, it creates a file with the same name but a specialize extension like ".RDY" or ".DONE".  App2(the always running app or service) uses FileSystemWatcher to watch that folder for any ".DONE" or ".RDY" files. If found, strips off the .RDY or .DONE and using that name finds the data file, reads it and acts upon it.  Erases both files.  App1 only needs to run long enough to create the input for app2.

2.) App2 always listens as a "server" on some local TCP/IP port, App1 communicates to it and closes

3.) Per MSDN, the other supported mechanisms are:

   "Clipboard
    COM
    Data Copy
    DDE
    File Mapping
    Mailslots
    Pipes
    RPC
    Windows Sockets"
source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx#base.using_pipes_for_ipc
I hope that your process is fast!

maybe have a look at http://emoreau.com/Entries/Articles/2008/11/Passing-arguments-to-an-
application-startup.aspx
Avatar of PNRT
PNRT

ASKER

Thank you both for the explanations.  I obviously haven't explained the scenario in enough detail.     I had thought of the alternatives but to explain further -

The system that calls my app is third party and I have no control over it.  It issues the command with the parameters and expects that the application will respond.

The app is not "called" continuously it may only be called once every few days or once a week.   But when it is it starts the process, it issues the commands at the rate of about 1 to 5 a second depending on the size of the file is has produced.  It may issue as many as two to five thousand commands/files  

The system calls my app with the name and path of a file as a parameter and expects this to be dealt with.

Hope this is more informative
if you have also created the application calling your second one (to which you pass arguments), instead of using arguments, you can surely use http://emoreau.com/Entries/Articles/2011/09/Using-SystemIOMemoryMappedFiles.aspx
Avatar of PNRT

ASKER

Thanks for the response Eric, the first link gives a page not found error and as per my update, the first app is not mine but a third party system.  Thanks again.
Hi PNRT,

This is a solution that was presented for the questions you had about using the Taskbar elements in Windows, but some of the elements of the code can be used for what you are attempting to accomplish.

https://www.experts-exchange.com/questions/28600426/vb-net-programming-the-Windows7-taskbar-icons.html?anchorAnswerId=40565503#a40565503

Recall that the solution presented above starts a new process that calls itself (this is what a JumpListLink essentially is) with command line parameters.

-saige-
If the files created by your third party are always in the same directory or in a system of subdirectories but with a filename pattern that can be identifiable, you might be able to cope with the problem with a FileSystemWatcher object. Instead of reacting to the calls from the third party, you would then react to the appearance of the files in the file system.
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@James Burger..I already mentioned that above.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial