I am developing a CLI-based console application in which most of the heavy-lifting work is performed via applets, scripts and command-line instructions.
SOME applets, however, do utilise WinForms, and this functionality has been added and works reasonably well, so long as the forms are activated via "Form.ShowDialog()" (as opposed to just "Form.Show()").
I assume that this is because the created form is sharing the messaging thread with the base (console-centric) application and the two aren't playing nice together.
After hashing it out, we've determined that we DON'T want to pause the CLI when a form is open (not the least because we want to be able to open multiple independent forms), so my guess is that I need to instantiate new forms in their own threads, but this idea is screaming "TOO COMPLEX!" at me, so I'm wondering if there's a more effective / streamlined means to accomplish this?
Can I somehow spawn a single thread, separate from the base one, on which all the forms can share (like in a standard Windows Forms application?) If so, how would I go about implementing that?
Currently, there are already three threads up and running -->
- The original (base) Console thread that I get when the EXE is originally executed.
- A thread that waits on Console.KeyAvailable and captures/manages all keystrokes and input parsing, as well as prompt display and instantiating invoked commands.
- A thread that manages a List of commands and processes any new commands that appear in that list (these can be added from the keyboard entry thread, or by an applet, or a script).
FWIW, "commands" are simply strings that instantiate an operation (runs an applet, accesses a built-in function etc).
When the "exit" function is called, it terminates the keyboard listening-thread, and then releases the command execution thread (on which it's running) thereby allowing it to exit and return control back to the operating system.
Currently, other than some occasionally sluggish responsiveness on the keyboard thread, everything works exactly as intended, except, as previously noted, when I try to instantiate a WinForm via .Show instead of .ShowDialog
Any insights, suggestions or pointers would be greatly appreciated!
Also: I read through some threads prior to posting this while looking for answers (i.e. this -> how to run a winform from console application? ) but they seem to all presuppose that the console pane will be used as it's native purpose (i.e. a Windows Console) as ooposed to being co-opted as am independent CLI interface, so I didn't find anything that really addressed this particular use-case, leaving me still somewhat in the dark at the moment! (and REALLY not wanting to contemplate having to write an underlying management engine for spawning/closing unique, independent threads for every form that gets opened!).
Thanks!