I'm trying to create an app with C# WPF to simulate Windows' command prompt, but with more flexibility and output options (like displaying images or forms). I recently got stuck on trying to simulate Console.ReadLine()
. I need to keep the GUI fully responsive, allowing the user to type input. At the same time, I need to be able to return
the answer from the same method.
I tried to solve this problem already by using events, but I can't figure out how to use them in a way that won't return void
. I looked into async
/ await
and a question about it, but couldn't quite figure out how to use that information. I considered an event-driven solution where the result would be stored in a permanent list variable for all of the inputs, which I could read the last of to get the latest input, but decided it wasn't good enough for what I'm simulating.
I plan on creating the console GUI in the main thread as soon as the application starts. However, I will be using logic from it in another thread which will be the meat of my code (I know it's not a professional way to program, but this is a personal project / learning experience, after all.) Then, I want to use some sort of custom ReadLine()
method to wait until the user submits text, then return it. If this is possible, how can it be done in WPF?