Closed
Description
With dotnet/designs#139 and #39269, we are marking Thread.Abort() as Obsolete because it unconditionally throws PlatformNotSupportedException. The tests for the PR turned up that ImageAnimator.Unix.cs uses Thread.Abort() inside StopAnimate.
public static void StopAnimate(Image image, EventHandler onFrameChangedHandler)
{
if (image == null)
return;
if (ht.ContainsKey(image))
{
AnimateEventArgs evtArgs = (AnimateEventArgs)ht[image]!;
evtArgs.RunThread!.Abort();
ht.Remove(image);
}
}I am going to put a #pragma warning disable around the Thread.Abort() call, but this code would be unexpectedly throwing PNSE right now, which means it's either dead code or there's a lurking bug that no one has reported.
Reacted by GSPP
Activity
jeffhandley commentedon Apr 25, 2021
Area owners (@maryamariyan @michaelgsharp @safern @tarekgh) -- Do you think it would be appropriate to mark
ImageAnimator.StopAnimateas[UnsupportedOSPlatform("unix")]since it's going to throw a PNSE if the image is animating? Or do you think we'd want to find a new way to implement animation stops such that it's not based on aborting threads?tarekgh commentedon Apr 25, 2021
I prefer if there is a way to avoid using Windows specific Thread.Abort and find equivalent on Linux. I am not even sure if Thread.Abort is the best option for Windows either.
CC @jkotas
jkotas commentedon Apr 25, 2021
Add a bool flag that gets set by
StopAnimateand the animation loop checks every iteration. It will match what the implementation does on Windows.