Exit Update Management

Using Squirrel.Windows , I wanted to handle the upgrade process in the Application Exit handler of my WPF application using this code:

Task.Run(async () => { using (var mgr = new UpdateManager(Settings.Default.UpdatePath)) { var release = await mgr.UpdateApp(); if (release != null && release.Version > Assembly.GetEntryAssembly().GetName().Version) { MessageBox.Show("Update applied"); } } }); 

This code works if I call it at startup or in an event handler at runtime, but not inside the application exit event handler, defined as follows:

App.xaml:

 <Application ... Exit="Application_Exit" ... 

App.xaml.cs:

 void Application_Exit(object sender, ExitEventArgs e) { ... } 

Is this a limitation of Squirrel.Windows? Or is there something special to use the code provided in the Exit Exit event handler?

0
c # wpf xaml squirrel.windows
Aug 18 '15 at 14:21
source share
1 answer

Since you create a hot Task that starts immediately, it will continue the next line of code. Presumably the next line of code is the end of your application exit handler. If you want to prevent this, follow these steps:

 Task.Run(async () => { //do stuff here }).Wait(); 

You can use the timeout / cancel functions by providing the appropriate Task.Wait arguments

+1
Aug 18 '15 at 14:57
source share



All Articles