question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Restarting an application in the same process doesn't work on Windows

See original GitHub issue

Take a look at my code here:

https://github.com/TylerLeonhardt/GraphicalTools/blob/4c06220400d4f6b64f3231528905753912db6cad/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs#L23-L88

It’s not too complex it mostly does:

            Application.Init();
            var top = Application.Top;
            top.RemoveAll();

            // Creates the top-level window to show
            var win = new Window(applicationData.Title ?? "Out-ConsoleGridView")
            {
                X = 0,
                Y = 1, // Leave one row for the toplevel menu
                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width = Dim.Fill(),
                Height = Dim.Fill()
            };
            top.Add(win);

            // Creates a menubar, the item "New" has a help menu.
            var menu = new MenuBar(new MenuBarItem []
            {
                new MenuBarItem("_Actions (F9)", 
                    applicationData.PassThru
                    ? new MenuItem []
                    {
                        new MenuItem("_Accept", "", () => { if (Quit("Accept", ACCEPT_TEXT)) top.Running = false; }),
                        new MenuItem("_Cancel", "", () =>{ if (Quit("Cancel", CANCEL_TEXT)) _cancelled = true; top.Running = false; })
                    }
                    : new MenuItem []
                    {
                        new MenuItem("_Close", "", () =>{ if (Quit("Close", CLOSE_TEXT)) top.Running = false; })
                    })
            });
            top.Add(menu);
            // add more stuff to win...

            Application.Run();

This code is run within PowerShell (since you can write PowerShell cmdlets in C#)… so it’s code that gets run in the same .NET process over and over again.

On macOS and Linux, this code works as expected. I can launch it (and quit it) over and over again and it shows the display over and over again.

On Windows, the first time works, but the second time it hangs without any ability to kill what’s running:

image

Any ideas what might be happening here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:32

github_iconTop GitHub Comments

2reactions
TylerLeonhardtcommented, Mar 9, 2020

image

I guess there are a few commits after the release!

2reactions
TylerLeonhardtcommented, Mar 7, 2020

@BDisp ~That fixes the issue!!~ (See https://github.com/migueldeicaza/gui.cs/issues/339#issuecomment-596123402) Thanks for the pointer. I’ll ping @migueldeicaza on twitter to see if he could look at that PR.

That would enable Out-ConsoleGridView on Windows 😃

btw here’s the blog post: https://devblogs.microsoft.com/powershell/introducing-consoleguitools-preview/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restarting an application in the same process doesn't work ...
I can launch it (and quit it) over and over again and it shows the display over and over again. On Windows, the...
Read more >
Programs not Opening unless restarted
Programs not Opening unless restarted · 1. Click the Start orb on your Desktop · 2. In the Start Search box. Type msconfig,...
Read more >
Applications do not start again after having been shut down ...
There can be many reasons why the forcibly terminated apps aren't starting back up. Perhaps file locks have not been released yet by...
Read more >
Why is my application is not starting up on Windows?
To kill the process, click on the process name, then select 'End Process' at the bottom of the window. After the process, you...
Read more >
Restarting windows form application
i have a windows application C#4.0 with multithreadings problem is when i close the application ,the process stays on, no matter what i...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found