Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Force Update on Open

Posted on 2013-01-03
8
Medium Priority
?
311 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:Ryan
  • 5
  • 3
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38741708
0
 
LVL 13

Author Comment

by:Ryan
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 13

Assisted Solution

by:Ryan
Ryan 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 2000 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:Ryan
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:Ryan
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:Ryan
ID: 38754110
Moving routine to a module allowed calling Restart, and single instance solved a created side effect.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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