I'm using Squirrel for installation and update process, that's why in my App.xaml.cs I handle custom Squirrel events
App.xaml.cs
public static event EventHandler ApplicationUpdated;
protected virtual void OnApplicationUpdated()
{
ApplicationUpdated?.Invoke(this, EventArgs.Empty);
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
try
{
using (var mgr = new UpdateManager(updateUrl))
{
SquirrelAwareApp.HandleEvents(
onInitialInstall: OnInitialInstall,
onAppUpdate: OnApplicationUpdate,
onAppUninstall: OnApplicationUninstall,
onFirstRun: OnFirstRun);
}
}
catch (Exception ex)
{ }
}
private void OnApplicationUpdate(Version version)
{
using (var manager = new UpdateManager(updateUrl))
{
manager.CreateShortcutsForExecutable(appFullName, ShortcutLocation.Desktop, true);
manager.CreateShortcutsForExecutable(appFullName, ShortcutLocation.StartMenu, true);
manager.CreateShortcutsForExecutable(appFullName, ShortcutLocation.AppRoot, true);
manager.RemoveUninstallerRegistryEntry();
manager.CreateUninstallerRegistryEntry();
}
System.Windows.Forms.MessageBox.Show("OnApplicationUpdated"); // this mbox is showing up normally
OnApplicationUpdated(); // here is where I fire event that notifies (or at least should notify) MainWindow about update
}
Update process and everything else (OnInitiallInstall etc) works correctly, but when I try to fire OnApplicationUpdated (it may be a bit confusing - it's my own static event) it doesn't fire(?) or MainWindow doesn't handle it properly, because method doesn't write single line in output nor changes any property of controls
MainWindow.xaml.cs
public MainWindow()
{
// some code above
App.ApplicationUpdated += App_ApplicationUpdated;
// some code under
}
private void App_ApplicationUpdated(object sender, EventArgs e)
{
Console.WriteLine("ApplicationUpdated");
Dispatcher.Invoke(() =>
{
updateLabel.Visibility = Visibility.Collapsed;
updateButton.Visibility = Visibility.Collapsed;
updateProgressRing.Visibility = Visibility.Collapsed;
restartButton.Visibility = Visibility.Visible;
});
}
Could you tell me why is this happening, why MainWindow doesn't handle this event?
I've been using static events like that for quite long time and never had any similar issue