NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
700 stars 145 forks source link

SYSLIB0006: `Thread.Abort` is not supported #407

Open jozefizso opened 9 months ago

jozefizso commented 9 months ago

The following APIs are marked obsolete, starting in .NET 5. Use of these APIs generates warning SYSLIB0006 at compile time and a PlatformNotSupportedException at run time.

When you call Thread.Abort to abort a thread other than the current thread, you don't know what code has executed or failed to execute when the ThreadAbortException is thrown. You also cannot be certain of the state of your application or any application and user state that it's responsible for preserving. For example, calling Thread.Abort may prevent the execution of static constructors or the release of managed or unmanaged resources. For this reason, Thread.Abort always throws a PlatformNotSupportedException on .NET Core and .NET 5+.

Workarounds

Use a CancellationToken to abort processing of a unit of work instead of calling Thread.Abort.

https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0006