Skip to content

DispatcherTimer should implement the IDisposable interface #8839

@odrouin

Description

@odrouin

We've learned the hard way that if Stop() is not called on DispatcherTimer instances, once they are started, they continue to live forever, even if nothing references the instance anymore.

After looking at the implementation of DispatcherTimer, we noticed that when calling Start(), a reference to the DispatcherTimer is added to the Dispatcher.CurrentDispatcher (which is static) and the reference is only removed once the Stop() method is called.
Now knowing that Stop() must always be called in order to avoid memory leaks, shouldn't the class implement IDisposable and make sure to call Stop() in the Dispose()? This would indicate the consumer of the class that it needs to be disposed for resources to be released.

Same way System.Threading.Timer implements IDisposable, I think DispatcherTimer should as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateRequires further investigation by the WPF team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions