MenuItem Click handlers lose connectivity when the socket connection is lost and re-established. #623

Closed
opened 2026-01-29 16:44:18 +00:00 by claunia · 3 comments
Owner

Originally created by @danatcofo on GitHub (Jan 28, 2021).

Originally assigned to: @GregorBiswanger on GitHub.

This is related to #442

Commenting on this issue can be found starting here.

the fix for #442 basically handled this same issue as it related to connectivity being lost to browser windows. Its been found that this same thing is happening to MenuItems as well.

You can reproduce this by :

public async void ElectronBootstrap(string myFolder)
{
    _browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
    {
        Width = 1366,
        Height = 768,
        MinWidth = 515,
        MinHeight = 300,
        Show = false
    });

    MenuItem openFolderMenuItem = new MenuItem
    {
        Label = "Open Folder",
        Click = () =>
        {
            Process.Start("explorer.exe", myFolder).Dispose();
        }
    };

    MenuItem launchDialog = new MenuItem
    {
        Label = "Launch Dialog",
        Click = () =>
        {
            Electron.Dialog.ShowErrorBox("My Dialog Tile", "This is my dialog.");
        }
    };

    MenuItem separator = new MenuItem
    {
        Type = MenuType.separator
    };

    MenuItem exitMenuItem = new MenuItem
    {
        Label = "Exit",
        Role = MenuRole.quit
    };

    MenuItem fileMenu = new MenuItem
    {
        Label = "File",
        Submenu = new MenuItem[] { openFolderMenuItem, launchDialog, separator, exitMenuItem },
        Type = MenuType.submenu
    };

    _browserWindow.SetMenu(new MenuItem[] { fileMenu });
    await _browserWindow.WebContents.Session.ClearCacheAsync();
    _browserWindow.OnReadyToShow += () => _browserWindow.Show();
}

and forcing the disconnect via CurrPorts which is a windows only app.

Originally created by @danatcofo on GitHub (Jan 28, 2021). Originally assigned to: @GregorBiswanger on GitHub. This is related to #442 Commenting on this issue can be found starting [here](https://github.com/ElectronNET/Electron.NET/issues/442#issuecomment-759624328). the fix for #442 basically handled this same issue as it related to connectivity being lost to browser windows. Its been found that this same thing is happening to MenuItems as well. You can reproduce this by : ```csharp public async void ElectronBootstrap(string myFolder) { _browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Width = 1366, Height = 768, MinWidth = 515, MinHeight = 300, Show = false }); MenuItem openFolderMenuItem = new MenuItem { Label = "Open Folder", Click = () => { Process.Start("explorer.exe", myFolder).Dispose(); } }; MenuItem launchDialog = new MenuItem { Label = "Launch Dialog", Click = () => { Electron.Dialog.ShowErrorBox("My Dialog Tile", "This is my dialog."); } }; MenuItem separator = new MenuItem { Type = MenuType.separator }; MenuItem exitMenuItem = new MenuItem { Label = "Exit", Role = MenuRole.quit }; MenuItem fileMenu = new MenuItem { Label = "File", Submenu = new MenuItem[] { openFolderMenuItem, launchDialog, separator, exitMenuItem }, Type = MenuType.submenu }; _browserWindow.SetMenu(new MenuItem[] { fileMenu }); await _browserWindow.WebContents.Session.ClearCacheAsync(); _browserWindow.OnReadyToShow += () => _browserWindow.Show(); } ``` and forcing the disconnect via [CurrPorts](https://www.nirsoft.net/utils/cports.html) which is a windows only app.
claunia added the bug label 2026-01-29 16:44:18 +00:00
Author
Owner

@Delpire commented on GitHub (Jan 28, 2021):

Some more information:

The menu items only stop working if the reason for the disconnect is transport closed. Other disconnections like ping timeout did not cause the menu items to break.

Additionally, it seems like its only the callbacks that are broken. MenuItems with roles like exit or toggling developer tools do not break.

@Delpire commented on GitHub (Jan 28, 2021): Some more information: The menu items only stop working if the reason for the disconnect is `transport closed`. Other disconnections like `ping timeout` did not cause the menu items to break. Additionally, it seems like its only the callbacks that are broken. MenuItems with roles like exit or toggling developer tools do not break.
Author
Owner

@danatcofo commented on GitHub (Jan 28, 2021):

note: on linux/osx, use this to close the socket without killing the pid

https://www.scm.keele.ac.uk/staff/stan/2016/05/16/closing-sockets-without-killing-processes/

@danatcofo commented on GitHub (Jan 28, 2021): note: on linux/osx, use this to close the socket without killing the pid https://www.scm.keele.ac.uk/staff/stan/2016/05/16/closing-sockets-without-killing-processes/
Author
Owner

@GregorBiswanger commented on GitHub (Mar 28, 2023):

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

@GregorBiswanger commented on GitHub (Mar 28, 2023): 🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉 With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#623