Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All!

I have a Windows form application with a listbox. The first item in this listbox comes in an Argument (Example: "application.exe c:\test.pdf"). Now i would like to add further items, when i open up next instance of my application with Argument. And the second instance have to be Close, if the item was added to the listbox. Can you post, how i can realize it in c#? Can anybody help with a snippet?

Thanks so much!

Greetz
HHubi2
Posted
Comments
CHill60 14-Nov-13 16:21pm    
If you are adding items to a list box from a command line argument then they will be lost when you close the application. Nor will any subsequent instance of the application know what the other instances contain. You probably need to persist this data somewhere.
It's not entirely clear what you are actually trying to achieve here
hhubi2 14-Nov-13 16:34pm    
Sorry for my bad english. I would like to keep the first instance open to add items / strings, when i open up the same application with a Argument, too.


example:

application.exe text.pdf [Enter] -> Application starts up and Listbox add item "text.pdf"
application.exe foo.pdf [Enter] -> Application cheching for existing process, add foo.pdf to first instance of application and close itself.

Now i have 2 items in my listbox: text.pdf and foo.pdf

I do not know, how i can can realize it... With mutex?

1 solution

Please see my past answer on communications between process instances and detection of single instance:
Enter multiple commands to only one process instance[^],
Custom Windows right-click command launching multiple instances[^].

As the most adequate mechanism for sending the file names to the first instance is just the command line, see also my article on this topic: Enumeration-based Command Line Utility[^].

My utility is the easiest to use, but I also recommend more complex and comprehensive one in the article.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900