Solved

Force Update on Open

Posted on 2013-01-03
8
303 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 46
Set form below another form 3 26
Showdialog 8 20
Red error squiggly on vb.net 7 12
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now