Solved

Force Update on Open

Posted on 2013-01-03
8
305 Views
Last Modified: 2013-01-08
I'm using clickonce, but I don't like having to change the minimum version number to force the update. It's less about forcing the update, as just not popping up the message box to the user asking if they want to update.

I don't care about installation times on startup, its typically only 5seconds or less, and the users are used to slower responses than that on most application startups.  As a programmer, if I publish an update, I want the users to be updated at a maximum of the next time it's executed, with minimal interference to them.

Here's what I've developed, but I can't figure out how to restart?  Am I in the wrong event?

The following code is in Application.Events
Partial Friend Class MyApplication

		Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
			If ApplicationDeployment.IsNetworkDeployed() Then
				If ApplicationDeployment.CurrentDeployment.CheckForUpdate Then
					ApplicationDeployment.CurrentDeployment.Update()
					'How do I force restart?
					'Application.Restart  ---This isn't available?
				End If

			End If
#If Not Debug Then
			ExManager.ExceptionManager.AddHandler()
#End If
		End Sub

	End Class

Open in new window

0
Comment
Question by:MrBullwinkle
  • 5
  • 3
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38741708
0
 
LVL 13

Author Comment

by:MrBullwinkle
ID: 38741726
I moved the routine out of the StartupEvent and into a module which allowed me to call Application.Restart, then called the module from the startup.  

It's all working, except that Restart doesn't close the current application, so I end up with 2 running, 1 old and 1 new.  Calling Application.Exit after Restart doesn't close the old one.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38741744
And what if you do this in main form load event?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 13

Assisted Solution

by:MrBullwinkle
MrBullwinkle earned 0 total points
ID: 38741782
Seems to be the same behavior if I call the sub from Startup Event, or from my initialForm's Load event.  It updates and opens the new app, but doesn't close the original.

Module modGlobals
	Public Sub UpdateAsNeeded()
		If ApplicationDeployment.IsNetworkDeployed() Then
			If ApplicationDeployment.CurrentDeployment.CheckForUpdate Then
				ApplicationDeployment.CurrentDeployment.Update()
				'How do I force restart?
				Application.Restart()
				Application.DoEvents()
				Application.Exit()
			End If

		End If
	End Sub
End Module

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38741828
Well that's weird because its description says

Shuts down the application and starts a new instance immediately.


Keep trying in different places (shown event as well) and it nothing else works then trying making the app a single instance app and see if that works.
0
 
LVL 13

Author Comment

by:MrBullwinkle
ID: 38741883
Turning on Single Instance did solve the problem.  I'm ok with using that option, it doesn't matter either way on my case.  Thanks.
0
 
LVL 13

Author Comment

by:MrBullwinkle
ID: 38741894
Hmm, well I just wanted to mark my final code as a solution and give credit for the single instance suggestion.  Didn't know it would cause a "close question".
0
 
LVL 13

Author Closing Comment

by:MrBullwinkle
ID: 38754110
Moving routine to a module allowed calling Restart, and single instance solved a created side effect.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question