Skip to content
Closed
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
@@ -1,9 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Diagnostics;
using static Interop;

namespace System.Windows.Forms
Expand Down Expand Up @@ -42,7 +43,13 @@ public void Dispose(bool disposing)
}
}

~NativeImageList() => Dispose(false);
~NativeImageList()
{
#if DEBUG
Debug.Fail($"{nameof(NativeImageList)} was not disposed properly. Originating stack:\n{_callStack}");
#endif
Dispose(false);
}
}
}
}
38 changes: 20 additions & 18 deletions src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ public virtual Image Image
get
{
Image image = (Image)Properties.GetObject(s_imageProperty);
if (image == null && (Owner != null) && (Owner.ImageList != null) && ImageIndexer.ActualIndex >= 0)
if (image == null && Owner?.ImageList?.HandleCreated == true && ImageIndexer.ActualIndex >= 0)
{
if (ImageIndexer.ActualIndex < Owner.ImageList.Images.Count)
{
Expand Down Expand Up @@ -2056,25 +2056,27 @@ private void Animate()

private void Animate(bool animate)
{
if (animate != _state[s_stateCurrentlyAnimatingImage])
if (animate == _state[s_stateCurrentlyAnimatingImage])
{
if (animate)
{
if (Image != null)
{
ImageAnimator.Animate(Image, new EventHandler(OnAnimationFrameChanged));
_state[s_stateCurrentlyAnimatingImage] = animate;
}
}
else
{
if (Image != null)
{
ImageAnimator.StopAnimate(Image, new EventHandler(OnAnimationFrameChanged));
_state[s_stateCurrentlyAnimatingImage] = animate;
}
}
return;
}

Image image = Image;
if (image == null)
{
return;
}

if (animate)
{
ImageAnimator.Animate(image, new EventHandler(OnAnimationFrameChanged));
}
else
{
ImageAnimator.StopAnimate(image, new EventHandler(OnAnimationFrameChanged));
}

_state[s_stateCurrentlyAnimatingImage] = animate;
}

internal bool BeginDragForItemReorder()
Expand Down