VB.NET StartupNextInstance and ClickOnce (.NET 2.0)

G

Guest

VB.NET StartupNextInstance and ClickOnce (.NET 2.0)

VB.NET StartupNextInstance and ClickOnce (.NET 2.0):
A call to ApplicationDeployment.CurrentDeployment.ActivationUri.Query
returns same paramaters in event handler MyApplication_StartupNextInstance as
it returns in MyApplication_Startup event handler.

Calls to ApplicationDeployment.CurrentDeployment.ActivationUri.Query in
event handler MyApplication_StartupNextInstance must return the query URL
parameters for applications starts after the initital startup. Meaning after
the inital startup of the application, any additional starts via ClickOnce
URL link with different parameters must be consumable from
MyApplication_StartupNextInstance via
ApplicationDeployment.CurrentDeployment.ActivationUri.Query. So, code has
access to URL query parameters of startups after the initial one.

I've noted a newsgroup response in MSDN Forums >> Windows Forms >> ClickOnce
and Setup & Deplyoment Projects >> StartupNextInstance and ClickOnce dated
23 Aug 2006, 1:21 AM UTC, Patty Lau responded this is a known bug.

Is this a known bug?
If so, is a fix available?

My apologies for reposting but my MSDN alias was not associated with my
account. This was corrected; I want to make sure my message is addressed.
 
L

Linda Liu [MSFT]

Hi,

Based on my understanding, you have a ClickOnce deployed VB.NET application
whose 'Make single instance application' feature has been turned on. You
lunch the application via a Url. When you lunch the application for the
first time, the Startup event is fired. When you lunch the application for
the second time, the StartupNextInstance event is raised. The problem is
that the call to
'ApplicationDeployment.CurrentDeployment.ActivationUri.Query' returns the
same result in the handler of the Startup event as it does in that of the
StartupNextInstance event. If I'm off base, please feel free to let me know.

I have performed a test based on my above understanding. I publish the
application to a Web site/ file path. I navigate the web page/shared file
path and lunch the application twice. The result is that the call to
'ApplicationDeployment.CurrentDeployment.ActivationUri.Query' in both the
handlers of Startup and StartupNextInstance events return NULL.

I have found an example on MSDN on how to retrieve the URL parameters by
using ActivationUri. You may have a try on it to see if it could solve your
problem.

'ApplicationDeployment.ActivationUri Property'
http://msdn2.microsoft.com/en-us/library/system.deployment.application.appli
cationdeployment.activationuri.aspx

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi Gene,

Thank you for your prompt response and pointing out the reason why I always
got NULL from calls to
'ApplicationDeployment.CurrentDeployment.ActivationUri.Query'.

I have performed more tests based on your suggestion and did see the same
thing as you did.

When we are attempting to lunch the single-instance application via a Url
for the second time, the "second process" is not lunched at all. It's in
the first process of the program that the StartupNextInstance event is
raised. So the call to
'ApplicationDeployment.CurrentDeployment.ActivationUri.Query' in the
StartupNextInstance event handler returns the activation Url of the first
process.

The above behavior makes sense, doesn't it?

We could use the CommandLine property of the e parameter in the
StartupNextInstance event to access the arguments for subsequent attempts
to start the single-instance application. But this doesn't help when we
lunch the application via a Url.

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

I still think this is a bug... If you search MSDN forums you will see one
reply that states this is... I was hoping you could confirm if it was or not.
From your reply, I assume it is not a known bug, maybe it is working as
design?

If anyone comes across this post and wants a reference to a working
solution, you may want to review "Making Windows Forms Work with Legacy Web
Applications" article which starts on page 10 in .NET Developer's Journal -
2005 Volume 3 Issue 11. The author walks you through creation of a single
instance, ClickOnce Web launched application that accepts Query String
parameters correctly for the first startup and next startup calls.

Thanks for your help,

Gene McCrory
 
L

Linda Liu [MSFT]

Hi Gene,

Thank you for pointing me to the "Making Windows Forms Work with Legacy Web
Application" article in .NET Developer's Journal. I have finished reading
it and know what the problem is in our scenario.

The sample introduced in this article uses a class named Program, which is
derived from
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class
to make the application single-instance. In detail, it sets the
IsSingleInstance property of the base class to true in the Program class's
constructor.

The sample retrieves the launch uri using
ApplicationDeployment.CurrentDeployment.ActivationUri property in the main
entry point for the application, i.e. the static Main method in the Program
class, and then creates a new Program instance. It calls the Run method of
the Progam instance and passes the launch uri string to the Run method as
the parameter, i.e. passes the new launch uri as the command lines to the
application.

In the override OnStartupNextInstance method within the Program class, we
could get current launch uri (i.e. the new launch uri when we're attempting
to launch the application for the second time) from the
StartupNextInstanceEventArgs parameter.

As we could see, the key point is that this sample passes the new launch
uri to the Program.Run method as the parameter in the static Main method,
so that we could get the current launch uri in the override
OnStartupNextInstance method later.

FYI, if we call the statement 'string uri =
ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri;' to get
the launch uri in the override OnStartupNextInstance method, we still get
the launch uri for the first time.

In our scenario, we're using a default sub Main as the main entry point for
the application, which doesn't get the current launch uri and pass it as
command lines to the application. So it's not strange that we couldn't get
the new launch uri from the StartupNextInstanceEventArgs parameter in the
StartupNextInstance event handler.

To work around this problem, we could add a class, e.g. Program, derived
from Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
class and set the startup object of the application to Sub Main in the
Project Designer (this requires that you disable application framework).

The following is the sample code of the Program class.

Imports System.Deployment.Application

Public Class Program
Inherits
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase

Public Shared Sub Main()

Dim uri As String =
ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri
Dim prog As New Program()
prog.MainForm = New Form1
Dim para As String() = New String() {uri}
prog.Run(para)
End Sub

Public Sub New()
Me.IsSingleInstance = True
End Sub

Protected Overrides Function OnStartup(ByVal eventArgs As
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) As Boolean
MsgBox("the first instance:" & eventArgs.CommandLine(0))
Return MyBase.OnStartup(eventArgs)
End Function

Protected Overrides Sub OnStartupNextInstance(ByVal eventArgs As
Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs)
MsgBox("the second instance:" & eventArgs.CommandLine(0))
MyBase.OnStartupNextInstance(eventArgs)
End Sub
End Class

I have performed a test on the above code and confirmed it works.

If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top