WebWindow icon indicating copy to clipboard operation
WebWindow copied to clipboard

NavigationManager stops sworking after closing and opening the app without terminating the process blazor

Open eivarin opened this issue 5 years ago • 1 comments

The navigation manager stops working after closing and opening the app. I'm using a windows forms notify icon and a custom application context to keep the process open even if the webwindow is closed but then when I go to reopen the webwindow under the same process it opens normally in the page that I was previously, but when i go to click a div that triggers a NavigationManager.NavigateTo(LinkName); it doesn't change page. I tried to debug this and, when I clicked a div that changes the page before closing it did this: image then this image and then run something with the dispatcher which looks to be made for error checking. After closing and reopening the webwindow I try to clicks a div that changes the page it did the same thing again but then when i clicked it again it didnt even debugged anymore. Note that while the buttons did nothing the HTML and css still worked as the hovers where still working

eivarin avatar May 01 '20 16:05 eivarin

So i managed to fix this, but since it isn't a general bug just one very specific for me I won't make a PR for it. The problem was the instance of DesktopNavigationManager was being kept the same between opening and closing the webwindow..... what I did was:

In the DesktopNavigationManager.cs I removed the protection from the instance: from this public static readonly DesktopNavigationManager Instance = new DesktopNavigationManager(); to this public static DesktopNavigationManager Instance = new DesktopNavigationManager();

and added a line that creates a new instance for DesktopNavigationManager whenever the application closes:

try{
                    WebWindow.NavigateToUrl(BlazorAppScheme + "://app/");
                    WebWindow.WaitForExit();
}
finally{
                    appLifetimeCts.Cancel();
                    //my code
                    DesktopNavigationManager.Instance = new DesktopNavigationManager();
}

eivarin avatar May 01 '20 18:05 eivarin