Skip to content

ImageAnimator.StopAnimate (on Unix) could throw PNSE #39405

Closed

Description

@jeffhandley

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.

Activity

  1. added
    untriaged
    on Jul 16, 2020
  2. removed
    untriaged
    on Jul 16, 2020
  3. added this to the Future milestone on Jul 16, 2020
  4. self-assigned this
    on Jan 8, 2021
  5. modified the milestones: Future, 6.0.0 on Jan 8, 2021
  6. jeffhandley commented on Apr 25, 2021

    @jeffhandley
    MemberAuthor

    Area owners (@maryamariyan @michaelgsharp @safern @tarekgh) -- Do you think it would be appropriate to mark ImageAnimator.StopAnimate as [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?

  7. tarekgh commented on Apr 25, 2021

    @tarekgh
    Member

    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

  8. jkotas commented on Apr 25, 2021

    @jkotas
    Member

    Add a bool flag that gets set by StopAnimate and the animation loop checks every iteration. It will match what the implementation does on Windows.

  9. ghost added
    in-pr
    on Apr 28, 2021
  10. ghost removed
    in-pr
    on May 1, 2021
  11. ghost added
    in-pr
    on May 4, 2021
  12. ghost removed
    in-pr
    on May 6, 2021
  13. ghost locked as resolved and limited conversation to collaborators on Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions