-1

I'm developing a console application and I am stuck with no ideia on how to handle this issue.

My issue is the following:

My application runs two threads (1) that generates output and (2) one that waits for user to write a line on the console. My issue is that sometimes thread 1 may write several lines into the console, "splitting" what the user is writing and thus confusing him on what has been written.

For now I am studying two possibilities:

(1) Opening two consoles, one for output and one for input. For this approach I already have an ideia from resources I found online, but I don't like this solution as much.

(2) Somehow, reserving a line or a few lines that show only what the user is writing into thread 2 and the rest of the lines to show the output generated by thread 1.

Is the approachable two feasible? Are there any resource available for me to study? Or is there a more used approach?

Thanks!

Ricardo Alves
  • 1,071
  • 18
  • 36

1 Answers1

0

The usual approach is use an exclusive thread for GUI interaction. Business logic can be done in different threads.

You are using a console, but it's the same idea. Only a thread should be allowed to interact with it.

amchacon
  • 1,891
  • 1
  • 18
  • 29
  • I see. Byt my application is running a Real-Time simulation of hardware, and so the window should pop-out what the "hardware" is outputting, while also allow the user to send commands to interact with the "hardware". – Ricardo Alves May 21 '19 at 22:53
  • Well you could launch two consoles, in that case, every GUI instance would have an exclusive thread. Anyway, i think that you need a proper GUI and not use a console – amchacon May 21 '19 at 22:54
  • @RicardoAlves If a desk-top GUI window is not an option, and if having two separate consoles seems awkward for your user, then you could try using _[ncurses](https://en.wikipedia.org/wiki/Ncurses)_. But, you'll still probably want to have a single thread that's responsible for the UI. – Solomon Slow May 22 '19 at 00:01