Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Thread.ResetAbort as obsolete #42228

Merged
merged 5 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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