C# simultanous console input and output?

后端 未结 7 508
我寻月下人不归
我寻月下人不归 2021-01-02 16:36

I am writing a server app and I want it to be console based. I need the user to be able to input different commands, but at the same time there is a possibility that somethi

7条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 17:17

    There's no perfect way of accomplishing this, I think. What telnet does (at least the last version I used) was not print any input (just read the keystrokes) and simply print the output as it arrives. The alternative is to store any data that needs to be output to the console in a buffer, and only print it once the user has finished entering their command. (You could even timestamp the output, to make it more obvious.) I really can't see any better alternative here - you're inevitably going to run into problems using a synchronous I/O interface (i.e. the command line) together with asynchronous operations in the backend.

提交回复
热议问题