From 888cc29e175f4ff28ed071fb41fcd459d5bbfd52 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Tue, 29 Oct 2024 17:56:32 +0800 Subject: [PATCH 1/4] Removing reference to ContextMenuStrip when dispose control --- src/System.Windows.Forms/src/System/Windows/Forms/Control.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 504df44ad99..b67159b74af 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -4695,6 +4695,7 @@ protected override void Dispose(bool disposing) } ReflectParent = null; + ContextMenuStrip = null; if (disposing) { From 186979d868bdd66b78cb8a76a7c2dccb654e8f17 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Thu, 31 Oct 2024 15:15:54 +0800 Subject: [PATCH 2/4] Merge 'main' to current branch --- eng/Version.Details.xml | 2 +- eng/Versions.props | 2 +- global.json | 2 +- src/System.Windows.Forms/src/System/Windows/Forms/Control.cs | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 40540a2f694..4258227c2ca 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -216,4 +216,4 @@ Note: if the Uri is a new place, you will need to add a subscription from that p e4df2888e714255352a6afa2ec1246e70ac21a49 - + \ No newline at end of file diff --git a/eng/Versions.props b/eng/Versions.props index 2c38c8ecaa2..2c8683e3a62 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -114,4 +114,4 @@ 8.0.1 - + \ No newline at end of file diff --git a/global.json b/global.json index e09c7c856fa..d7e4f8c02eb 100644 --- a/global.json +++ b/global.json @@ -23,4 +23,4 @@ "native-tools": { "cmake": "latest" } -} +} \ No newline at end of file diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index bb8a077b57b..c4219601d70 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -4694,6 +4694,7 @@ protected override void Dispose(bool disposing) } } + ContextMenuStrip = null; ReflectParent = null; ContextMenuStrip = null; From a6a4ac9b7cbe0189092a082d540b09c30af414b4 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Thu, 31 Oct 2024 15:50:56 +0800 Subject: [PATCH 3/4] Detach ContextMenuStrip from control when executing Dispose --- eng/Version.Details.xml | 2 +- eng/Versions.props | 2 +- global.json | 2 +- .../src/System/Windows/Forms/Control.cs | 9 +++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 4258227c2ca..40540a2f694 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -216,4 +216,4 @@ Note: if the Uri is a new place, you will need to add a subscription from that p e4df2888e714255352a6afa2ec1246e70ac21a49 - \ No newline at end of file + diff --git a/eng/Versions.props b/eng/Versions.props index 2c8683e3a62..2c38c8ecaa2 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -114,4 +114,4 @@ 8.0.1 - \ No newline at end of file + diff --git a/global.json b/global.json index d7e4f8c02eb..e09c7c856fa 100644 --- a/global.json +++ b/global.json @@ -23,4 +23,4 @@ "native-tools": { "cmake": "latest" } -} \ No newline at end of file +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index c4219601d70..f4353f2080c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -4694,9 +4694,14 @@ protected override void Dispose(bool disposing) } } - ContextMenuStrip = null; + // Unsubscribes from the Disposed event of the ContextMenuStrip. + ContextMenuStrip? menu = ContextMenuStrip; + if (menu is not null) + { + menu.Disposed -= DetachContextMenuStrip; + } + ReflectParent = null; - ContextMenuStrip = null; if (disposing) { From 8fa5b5f0806a3e67fb0e4d0cdfa530b39f627143 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Fri, 1 Nov 2024 09:48:24 +0800 Subject: [PATCH 4/4] Use pattern matching for judge variable menu --- src/System.Windows.Forms/src/System/Windows/Forms/Control.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index f4353f2080c..1a5b685651b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -4695,8 +4695,7 @@ protected override void Dispose(bool disposing) } // Unsubscribes from the Disposed event of the ContextMenuStrip. - ContextMenuStrip? menu = ContextMenuStrip; - if (menu is not null) + if (ContextMenuStrip is ContextMenuStrip menu) { menu.Disposed -= DetachContextMenuStrip; }