From 6d67541c5a40736a5b12a3f3ec54aa3334365087 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+TheRealHona@users.noreply.github.com> Date: Tue, 15 Sep 2020 09:44:07 +1000 Subject: [PATCH 1/5] Mark Thread.ResetAbort as obsolete --- .../System.Threading.Thread/ref/System.Threading.Thread.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs index 3fe3aea58faf75..bd511d1705471b 100644 --- a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs +++ b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs @@ -77,6 +77,7 @@ public void Join() { } public bool Join(int millisecondsTimeout) { throw null; } public bool Join(System.TimeSpan timeout) { throw null; } public static void MemoryBarrier() { } + [System.ObsoleteAttribute("Thread.ResetAbort is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0006", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static void ResetAbort() { } [System.ObsoleteAttribute("Thread.Resume has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)] public void Resume() { } From f9ae0c0b678cc98f6e031942f122027833e05999 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+TheRealHona@users.noreply.github.com> Date: Tue, 15 Sep 2020 10:51:51 +1000 Subject: [PATCH 2/5] Mark Thread.ResetAbort as obsolete in src --- .../System.Private.CoreLib/src/System/Threading/Thread.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs index ba36c3f14fa307..bf85ffe8d78be2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs @@ -189,6 +189,7 @@ public void Abort(object? stateInfo) throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadAbort); } + [Obsolete(Obsoletions.ThreadAbortMessage, DiagnosticId = Obsoletions.ThreadAbortDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static void ResetAbort() { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadAbort); From 8e432a08af460b933f0eaecac11c5446401d13ea Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+TheRealHona@users.noreply.github.com> Date: Tue, 15 Sep 2020 10:57:17 +1000 Subject: [PATCH 3/5] Don't wrap the LoopHandler with try/catch --- .../src/System/Drawing/ImageAnimator.Unix.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs index 0bafe3e36be07e..4ecbc1036662d1 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs @@ -179,20 +179,13 @@ public WorkerThread(EventHandler frmChgHandler, AnimateEventArgs aniEvtArgs, int public void LoopHandler() { - try + int n = 0; + while (true) { - int n = 0; - while (true) - { - Thread.Sleep(delay[n++]); - frameChangeHandler(null, animateEventArgs); - if (n == delay.Length) - n = 0; - } - } - catch (ThreadAbortException) - { - Thread.ResetAbort(); // we're going to finish anyway + Thread.Sleep(delay[n++]); + frameChangeHandler(null, animateEventArgs); + if (n == delay.Length) + n = 0; } } } From 7086e2f9776f268697d5a0b09231b0c9bdc5056e Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+TheRealHona@users.noreply.github.com> Date: Tue, 15 Sep 2020 11:30:42 +1000 Subject: [PATCH 4/5] Move Thread.ResetAbort test into obsolete section --- .../System.Threading.Thread/tests/ThreadTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs index 66d8250f5fea75..2e5b7274a6ac52 100644 --- a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs +++ b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs @@ -732,12 +732,13 @@ public static void AbortSuspendTest() Action verify = () => { -#pragma warning disable SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume +#pragma warning disable SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume, ResetAbort Assert.Throws(() => t.Abort()); Assert.Throws(() => t.Abort(t)); + Assert.Throws(() => t.ResetAbort()); Assert.Throws(() => t.Suspend()); Assert.Throws(() => t.Resume()); -#pragma warning restore SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume +#pragma warning restore SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume, ResetAbort }; verify(); @@ -745,9 +746,7 @@ public static void AbortSuspendTest() verify(); e.Set(); - waitForThread(); - - Assert.Throws(() => Thread.ResetAbort()); + waitForThread(); } private static void VerifyLocalDataSlot(LocalDataStoreSlot slot) From 4a8eedf67111b0f8e3d10dc29cc64ee67f23d03e Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+TheRealHona@users.noreply.github.com> Date: Tue, 15 Sep 2020 12:05:14 +1000 Subject: [PATCH 5/5] Use type name instead of instance --- src/libraries/System.Threading.Thread/tests/ThreadTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs index 2e5b7274a6ac52..cad955cce41a9b 100644 --- a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs +++ b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs @@ -735,7 +735,7 @@ public static void AbortSuspendTest() #pragma warning disable SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume, ResetAbort Assert.Throws(() => t.Abort()); Assert.Throws(() => t.Abort(t)); - Assert.Throws(() => t.ResetAbort()); + Assert.Throws(() => Thread.ResetAbort()); Assert.Throws(() => t.Suspend()); Assert.Throws(() => t.Resume()); #pragma warning restore SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume, ResetAbort