Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 3d51fd4

Browse files
netonjmmonojenkins
authored andcommitted
Handles disposed windows when they are closed while the windows loop
Fixes VSTS #999372 - System.ObjectDisposedException exception in Foundation.NSObject.get_SuperHandle()
1 parent 251bc47 commit 3d51fd4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/WindowCommands.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,38 @@ internal class OpenWindowListHandler : CommandHandler
253253
protected override void Update (CommandArrayInfo info)
254254
{
255255
foreach (Components.Window window in IdeApp.CommandService.TopLevelWindowStack) {
256+
257+
string title = null;
258+
bool hasTopLevel = false;
259+
260+
try {
261+
title = window.Title;
262+
hasTopLevel = window.HasTopLevelFocus;
256263
#if !WINDOWS
257-
//we don't want include hidden windows
258-
if (!window.IsRealized || !window.IsVisible || Components.Mac.GtkMacInterop.IsGdkQuartzWindow (window))
259-
continue;
264+
//we don't want include hidden windows
265+
if (!window.IsRealized || !window.IsVisible || Components.Mac.GtkMacInterop.IsGdkQuartzWindow (window))
266+
continue;
260267
#endif
268+
} catch (System.ObjectDisposedException) {
269+
//this means the window was closed while the loop then we want continue to next element
270+
continue;
271+
}
272+
261273

262274
//Create CommandInfo object
263275
var commandInfo = new CommandInfo ();
264-
commandInfo.Text = window.Title.Replace ("_", "__").Replace ("-", "\u2013").Replace (" \u2013 " + BrandingService.ApplicationName, "");
276+
commandInfo.Text = title.Replace ("_", "__").Replace ("-", "\u2013").Replace (" \u2013 " + BrandingService.ApplicationName, "");
265277

266278
if (string.IsNullOrEmpty (commandInfo.Text)) {
267279
commandInfo.Text = GettextCatalog.GetString ("No description");
268280
}
269281

270-
if (window.HasTopLevelFocus)
282+
if (hasTopLevel)
271283
commandInfo.Checked = true;
272284
commandInfo.Description = GettextCatalog.GetString ("Activate window '{0}'", commandInfo.Text);
273285

274286
//Add menu item
275-
info.Add (commandInfo, window.Title);
287+
info.Add (commandInfo, title);
276288
}
277289
}
278290

0 commit comments

Comments
 (0)