I am adding the debugging functionality to Small Visual Basic language (written with VB .NET), which I built on top of MS Small Basic (Written with C#). I have two issues:
Issue 1: The SB/sVB TextWindow represents the Console window, and it works fine when it is accessed from a separate process (like running the exe files compiled by the language), but it has troubles in the debug mode. The TextWindow (Console) doesn't work in debug mode. It is inactive and user can't write into it. The code uses win32 APIs to show the console, then uses the System.Console class method to interact with it. In WinForms and WPF project, this will interact with Output Window not the console window. This is the exception I get when I try to read a key: System.InvalidOperationException: 'Cannot read keys when either application does not have a console or when console input has been redirected from a file.
Edit: I found a solution for this issue: I discovered that the console window doesn't work when I run the sVB project in VS .NET in debugging mode, but if I run it without debugging, or launch the sVB.EXE outside VS .NET, the console window works, and this is fine with me. So, issue 1 is already solved, but issue 2 still needs a solution.
Issue 2: The console window terminates the whole process when it is closed, and I can't find a way to prevent that. I've read similar topics here, but I couldn't find a proper solution. For example, disabling the close button is not a full solution, because user can still press Ctrl+C. I also tried using the SetConsoleCtrlHandler to and intercept the close event, but I couldn't cancel terminating the process. Note that closing the process while running in the debugging mode closes sVB itself! This is also an issue when running any app.exe as closing the console while other windows are open will close them all!
Is there any solution for these issues? And if not, can I use a normal window for the TextWindow, and if so how to make the code execution wait for the return of the Read methods until the user submits his input in such a window? Thanks.
I found a solution for the first issue: I discovered that the console window doesn't work when I run the sVB project in VS .NET in debugging mode, but if I run it without debugging, or launch the sVB.EXE outside VS .NET, the console window works, and this is fine with me. I wish if VS debugger can solve this issue, but I can live with it. So, issue 1 can be considered solved.
Regarding issue 2: Currently. I just disabled the close button of the console window as explained here, so, the user will have to press any key to close the window, but the code will actually hide it unless it is the last opened window in the project. This is a good workaround, but the user can still press Ctrl+C to close the window. In fact this is not likely specially by kids and adults that use sVB, so, I will live with this, until someone comes with a full solution. The code I used in the project exists in the TextWindow.Show method, and the related APIs exist in the NativeHelper class. Thanks.