<appStart> <ClientApplicationInfo> <appFolderName>C:\PagePlanner\1.6.1.0</appFolderName> <appExeName>PagePlan.exe</appExeName> <installedVersion>1.6.1.0</installedVersion> <lastUpdated>2003-07-16T10:50:36.7831101-07:00</lastUpdated> </ClientApplicationInfo> </appStart>
Next, it was time to modifiy my application's code and .config file... because it handles the actual update work.
#Region "App Updater Declares" Private WithEvents _updater As _ ApplicationUpdateManager = Nothing Private _updaterThread As Thread = Nothing Private Const UPDATERTHREAD_JOIN_TIMEOUT _ As Integer = 3 * 1000 Private WithEvents myDomain As _ AppDomain = AppDomain.CurrentDomain #End Region
Private Sub InitializeAutoUpdate() _updater = New ApplicationUpdateManager ' start the updater on a separate thread _ 'so that our UI remains responsive _updaterThread = New Thread( _ New ThreadStart(AddressOf _updater.StartUpdater)) _updaterThread.Start() End Sub
Private Sub _updater_FilesValidated( _ ByVal sender As Object, _ ByVal e As UpdaterActionEventArgs) _ Handles _updater.FilesValidated Me.BeginInvoke(New MarshalEventDelegate( _ AddressOf Me.OnUpdaterFilesValidatedHandler), _ New Object() {sender, e}) End Sub Private Sub OnUpdaterFilesValidatedHandler( _ ByVal sender As Object, _ ByVal e As UpdaterActionEventArgs) Dim dialog As DialogResult = _ MessageBox.Show( _"Would you like to stop this application and open the new version?", _"Open New Version?", MessageBoxButtons.YesNo) If DialogResult.Yes = dialog Then StartNewVersion(e.ServerInformation) End If End Sub Private Sub _updater_UpdateAvailable( _ ByVal sender As Object, _ ByVal e As UpdaterActionEventArgs) _ Handles _updater.UpdateAvailable Me.Invoke(New MarshalEventDelegate( _ AddressOf Me.OnUpdateAvailableHandler), _ New Object() {sender, e}) End Sub Private Sub OnUpdateAvailableHandler( _ ByVal sender As Object, _ ByVal e As UpdaterActionEventArgs) Debug.WriteLine(("Thread: " + _ Thread.CurrentThread.GetHashCode().ToString())) Dim message As String = _ String.Format("Update available: The new version on the server is {0} and current version is {1} would you like to upgrade?", _ e.ServerInformation.AvailableVersion, _ ConfigurationSettings.AppSettings("version")) Dim dialog As DialogResult = _ MessageBox.Show(message, _ "Update Available", MessageBoxButtons.YesNo) ' for update available we actually WANT to block 'the downloading thread so we can refuse an update ' and reset until next polling cycle; ' NOTE that we don't block the thread _in the UI_, 'we have it blocked at the marshalling dispatcher '"OnUpdaterUpdateAvailable" If DialogResult.No = dialog Then ' if no, stop the updater for this app _updater.StopUpdater(e.ApplicationName) End If End Sub Private Sub myDomain_ProcessExit(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles myDomain.ProcessExit StopUpdater() End Sub Private Sub frmMain_Closed( _ ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Closed StopUpdater() End Sub Delegate Sub MarshalEventDelegate( _ ByVal sender As Object, _ ByVal e As UpdaterActionEventArgs)
Private Sub StartNewVersion( _ ByVal server As ServerApplicationInfo) ' NOTE: this pathing trick will ONLY work when ' this app is run from the expected "1.0.0.0" ' sub-dir of the demo; ' it expects to have AppStart.exe in dir directly ' above it, as would be case in demo. Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument Dim basePath As String doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) basePath = doc.SelectSingleNode( _"configuration/appUpdater/UpdaterConfiguration/application/client/baseDir").InnerText Dim newDir As String = Path.Combine(basePath, "AppStart.exe") Dim newProcess As New ProcessStartInfo(newDir) newProcess.WorkingDirectory = newDir + server.AvailableVersion ' launch new version (actually, launch AppStart.exe which ' HAS pointer to new version ) Process.Start(newProcess) ' tell updater to stop myDomain_ProcessExit(Nothing, Nothing) ' leave this app Environment.Exit(0) End Sub Private Sub StopUpdater() ' tell updater to stop _updater.StopUpdater() If Not (_updaterThread Is Nothing) Then ' join the updater thread with a suitable timeout Dim isThreadJoined As Boolean = _ _updaterThread.Join(UPDATERTHREAD_JOIN_TIMEOUT) ' check if we joined, if we didn't interrupt the thread If Not isThreadJoined Then _updaterThread.Interrupt() End If _updaterThread = Nothing End If End Sub
<appSettings> <add key="version" value="1.6.1.0" ü> FONT color=#800000>appSettings>
<logListener logPath="C:\PagePlanner\UpdaterLog.txt" />
<application name="PagePlanner" useValidation="true"> <client> <baseDir>C:\PagePlanner\FONT color=#800000>baseDir> <xmlFile>C:\PagePlanner\AppStart.exe.configFONT color=#800000>xmlFile> <tempDir>C:\PagePlanner\newFilesFONT color=#800000>tempDir> FONT color=#800000>client> <server> <xmlFile>http://darkmajesty/PagePlan/Manifest.xmlFONT color=#800000>xmlFile> <xmlFileDest>C:\PagePlanner\Manifest.xmlFONT color=#800000>xmlFileDest> <maxWaitXmlFile>60000FONT color=#800000>maxWaitXmlFile> FONT color=#800000>server> FONT color=#800000>application>
<appSettings> <add key="version" value="1.6.2.0"> FONT color=#800000>appSettings>