mirror of
https://github.com/AlexMacocian/WpfExtended.git
synced 2026-07-21 01:19:29 +00:00
Implemented application lifetime management.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user