SYSLIB0059: SystemEvents.EventsThreadShutdown callbacks aren't run before the process exits
The SystemEvents.EventsThreadShutdown event is obsolete, starting in .NET 10. Referencing this event in code generates warning SYSLIB0059
at compile time.
Reason for obsoletion
The previous shutdown handling in SystemEvents could block the finalizer thread during app shutdown. To avoid blocking the finalizer thread, SystemEvents no longer has shutdown handling, which means that the SystemEvents.EventsThreadShutdown event is no longer called. To surface this behavior change, the event was marked obsolete.
Workaround
Use AppDomain.ProcessExit instead.
Suppress a warning
If you must use the obsolete API, you can suppress the warning in code or in your project file.
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
// Disable the warning.
#pragma warning disable SYSLIB0059
// Code that uses obsolete API.
// ...
// Re-enable the warning.
#pragma warning restore SYSLIB0059
To suppress all the SYSLIB0059
warnings in your project, add a <NoWarn>
property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);SYSLIB0059</NoWarn>
</PropertyGroup>
</Project>
For more information, see Suppress warnings.
.NET