Skip to content

Commit

Permalink
Mark Thread.ResetAbort as obsolete (#42228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hona committed Sep 15, 2020
1 parent 3cd27af commit 60aa3be
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Expand Down
9 changes: 4 additions & 5 deletions src/libraries/System.Threading.Thread/tests/ThreadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,22 +732,21 @@ 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<PlatformNotSupportedException>(() => t.Abort());
Assert.Throws<PlatformNotSupportedException>(() => t.Abort(t));
Assert.Throws<PlatformNotSupportedException>(() => Thread.ResetAbort());
Assert.Throws<PlatformNotSupportedException>(() => t.Suspend());
Assert.Throws<PlatformNotSupportedException>(() => t.Resume());
#pragma warning restore SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume
#pragma warning restore SYSLIB0006, 618 // Obsolete: Abort, Suspend, Resume, ResetAbort
};
verify();

t.Start();
verify();

e.Set();
waitForThread();

Assert.Throws<PlatformNotSupportedException>(() => Thread.ResetAbort());
waitForThread();
}

private static void VerifyLocalDataSlot(LocalDataStoreSlot slot)
Expand Down

0 comments on commit 60aa3be

Please sign in to comment.