Skip to content

Commit

Permalink
Detach ContextMenuStrip from control when executing Dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafShi1 committed Oct 31, 2024
1 parent 186979d commit c8e0d8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ Note: if the Uri is a new place, you will need to add a subscription from that p
<Sha>e4df2888e714255352a6afa2ec1246e70ac21a49</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
</Dependencies>
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@
<!-- Pin transitive dependency to avoid vulnerable 8.0.0 version. -->
<SystemFormatsAsn1PackageVersion>8.0.1</SystemFormatsAsn1PackageVersion>
</PropertyGroup>
</Project>
</Project>
8 changes: 6 additions & 2 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4694,9 +4694,13 @@ protected override void Dispose(bool disposing)
}
}

ContextMenuStrip = null;
// Unsubscribes from the Disposed event of the ContextMenuStrip.
if (ContextMenuStrip is not null)
{
ContextMenuStrip.Disposed -= DetachContextMenuStrip;
}

ReflectParent = null;
ContextMenuStrip = null;

if (disposing)
{
Expand Down

0 comments on commit c8e0d8e

Please sign in to comment.