Command Lines and Instances

wldrumstcs

New member
Joined
Dec 18, 2006
Messages
2
Programming Experience
1-3
I have the following code that will add the command lines to an arraylist. My question is, if I make my program a single instance program, how would I pass any subsequent command lines to the main instance of my program? In other words, if I open up abc.mp3 in my media player, and then click on 123.mp3 from my Desktop, how would I send '123.mp3' to my main form? Also, where should I put my provided code to achieve this? Right now, it's in the 'Load' event, but I imagine it should be elsewhere.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cla [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]() = Environment.GetCommandLineArgs()[/SIZE]
 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] cla.Length > 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] IO.File.Exists(cla(1)) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] filenamearray [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ArrayList()[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] cla.Length - 1[/SIZE]
[SIZE=2]filenamearray.Add(cla(i))[/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
 
i dont know how to explain the ability to do this, but you could add a public Enqueue method, and when another instance is being opened, simply refer it to the previous instance via the Enqueue method
 
VB 2005 provides this functionality for you. You simply handle the StartupNextInstance event of the application. Go to the Application tab of the project properties and press the View Application Events button, then use the drop-down lists at the top of the code window to create the event handler.
 
Back
Top