Terminal.Gui: Restarting an application in the same process doesn't work on Windows
Take a look at my code here:
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:

Any ideas what might be happening here?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 32
I guess there are a few commits after the release!
@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/
Of course. I’m also preparing more pr’s with some features too.
I guess we can close this 😅 and then wait for a new release.
cc @migueldeicaza
Wow you’re totally right. It does work!