Implemented application lifetime management.

This commit is contained in:
Alexandru Macocian
2021-04-01 14:19:16 +02:00
parent c341f01abe
commit 127cfd749f
3 changed files with 34 additions and 1 deletions
+8
View File
@@ -15,6 +15,14 @@ namespace WpfExtended.Tests
return Instance.Run();
}
protected override void ApplicationClosing()
{
}
protected override void ApplicationStarting()
{
}
protected override bool HandleException(Exception e)
{
return false;
+25
View File
@@ -18,6 +18,14 @@ namespace System.Windows.Extensions
this.RegisterInternals();
}
/// <summary>
/// Called right before the window is shown.
/// </summary>
protected abstract void ApplicationStarting();
/// <summary>
/// Called right before the application is closing.
/// </summary>
protected abstract void ApplicationClosing();
/// <summary>
/// Register services into the <see cref="IServiceProducer"/>.
/// </summary>
@@ -34,12 +42,25 @@ namespace System.Windows.Extensions
{
this.SetupExceptionHandling();
this.RegisterServices(this.ServiceManager);
this.SetupApplicationLifetime();
this.LaunchWindow();
}
protected sealed override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
this.ApplicationClosing();
}
protected sealed override void OnSessionEnding(SessionEndingCancelEventArgs e)
{
base.OnSessionEnding(e);
this.ApplicationClosing();
}
private void LaunchWindow()
{
var window = this.ServiceManager.GetService<T>();
this.ApplicationStarting();
window.Show();
}
private void RegisterInternals()
@@ -70,5 +91,9 @@ namespace System.Windows.Extensions
}
};
}
private void SetupApplicationLifetime()
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => this.ApplicationClosing();
}
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>License.txt</PackageLicenseFile>
<Version>0.1</Version>
<Version>0.1.1</Version>
<Description>Extension library for Windows Presentation Platform.
Credits: