Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > nextinstance
 

nextinstance

hi,

i wrote a single instance application - a pic viewer. if i double click on an picture file it opens up my app with that file. now if my program is runnin and i open up one more pic i'd like my program change the shown pic to the new - i know i have to write this in the application events, the StartupNextInstance event but don't know how to get the path of the second pic.

any idea?

thnx

Attila Fogel  Sunday, June 25, 2006 12:06 PM
You can retrieve the command line from e.CommandLine in the StartupNextInstance event handler.

nobugz  Sunday, June 25, 2006 1:33 PM
You can retrieve the command line from e.CommandLine in the StartupNextInstance event handler.

nobugz  Sunday, June 25, 2006 1:33 PM
What if it's a clickonce applciation?
NeilG  Thursday, August 03, 2006 1:39 PM
Should work the same way. Having problems?
nobugz  Thursday, August 03, 2006 1:48 PM
CommandLine is empty for a clickonce application.

When opening the application I can check do this
If My.Application.IsNetworkDeployed Then
'Get URI deployed from
Dim zUri As New Uri(My.Application.Deployment.ActivationUri.AbsoluteUri)
'Get query string (clear the ?)
zstrQuery = zUri.Query.Replace("?", String.Empty)
'Split it
zarr_strArgs = zstrQuery.Split("&".ToCharArray)
End If

But if it's the second instance, the CommandLine is empty and I don't seem to have any way to access the ActivationUri of the second instance.



NeilG  Thursday, August 03, 2006 2:05 PM
I think you're on the wrong track, the ActivationUri property is undocumented but sounds like the URL where you'd obtain an upgrade. I don't know enough about ClickOnce, I'd recommend you start a new thread in the VB.NET General forum, this one is already marked as answered so attracks few visitors...
nobugz  Thursday, August 03, 2006 2:48 PM
I did. I was just making replies to other threads where someone might have an answer as well.

The ActivationUri is documented here as part of the 2.0 framework.
http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.activationuri.aspx

and from this page
http://msdn2.microsoft.com/en-us/library/z2d603cy.aspx

In an application that is ClickOnce deployed, use the ActivationUri property of the My.Application.Deployment object to get the command-line arguments.


The problem with the StartupNextInstance is that it assumes the application is being launched as a normal application. A ClickOnce deployed application can be launced with startup paramaters via a querystring in a URL, but that's not accessible from StartupNextInstanceEventArgs


NeilG  Thursday, August 03, 2006 4:50 PM

You are on the wrong track - starting up your application passes command line parameters. The Network Deployment properties of the applicaton objectis a completely different beast and is designed to allow the application to check for updates from the network deployment location (it's powerful enough to do other things too). Using these parameters in the startup next instance makes no sense. Clickonce is also designed to have it run from a networklocation (which is different from having it run over a network, btw). (I will admit that I'm no fan of ClickOnce - its a darned awful thing, or anything other than the most trivial of application).

Use the e.CommandLine: It appears that is what you want. In fact, you should try it, see what happens. Presumably, somehow you have associated 'files' with your application...

SJWhiteley  Friday, August 04, 2006 12:17 PM
That won't work. We're using ClickOnce deployment in our organization.

The users always launch the application from a URL to insure they are using the current version.
Sometimes, the URL contains additional paramaters so that they are taken directly to an area of the application.

When they open the app a second time and they already have an instance we want it to re-use the first instance but pass the paramaters from the 2nd.

So the CommandLine isn't an option. I may not be able to use the StartupNextInstance event, and that's fine, but I'd like to think there's a solution to this somewhere


NeilG  Friday, August 04, 2006 12:23 PM

What does the URI show when you've selected single instance app, and the user re-clicks the application? Try with a timer or something to see if it changes.

If it doesn't, it likely you will have to make it a deployed application, or live with the fact you can't do what you want because 'this is the way it must be done' (not sure why, seems a bit shortsighted, to me, sorry - starting to rant...danger will robinson, danger!...).

The whole point of the Url thing is that the application can check for updates automatically, so keeping it 'network deployed' doesn't necessarily mean you are gaining that feature, and loosing it if it isn't.

SJWhiteley  Friday, August 04, 2006 12:34 PM
The URI doesn't change when the second instance is opened.
Thanks for your help.

NeilG  Friday, August 04, 2006 1:10 PM

You can use google to search for other answers

Custom Search

More Threads

• TabControl.TabPages Weird Problem
• Adding Master/Detail records to SQL DB from VB.NET in code
• get combobox value
• How can I control power to a USB port
• How to create and display email message?
• Checking rows, columns and grids in a 1 dimensional array
• SAP and .Net
• Making my program customise and generate an exe
• Combobox, SQL 2005 and foreign keys
• Determine a DLL's language