I'm developing an application using C# with Avalonia framework. When system shuts down I need to perform some tasks (write logs and metadata to files) for application to complete job gracefully.
Previously using WPF on Windows I used subscription to Microsoft.Win32.SystemEvents.SessionEnding
event. But as namespace says, it is OS dependent.
In Avalonia I tried to handle AppDomain.CurrentDomain.ProcessExit
or ((IClassicDesktopStyleApplicationLifetime)ApplicationLifetime).Exit
events but neither of them fired.
So, question is, what is the correct way to handle OS shutdown on both systems.
Asked
Active
Viewed 1,099 times
3

Yuri Plokhih
- 31
- 4
1 Answers
2
You should try the shutdown event, it's signature is as follows...
((IClassicDesktopStyleApplicationLifetime)ApplicationLifetime).ShutdownRequested += delegate(object? sender, ShutdownRequestedEventArgs e)
{
//Write logs and metadata to files here...
};

Lyle February
- 136
- 6