This question already has answers here:
C# allow simultaneous console input and output
(4 answers)
Closed 5 years ago.
I have a console app that is running multiple worker threads. I would like the console output to have one WriteLine to report the status of each thread. I know I can simply clear, and loop through my threads to report their status on some interval, but at the same time I want to type commands that would be processed by the application using ReadLine(). Is there a common approach to maintain the top x lines of a console to show scrolling or updated info, and have a line below them where I can type in commands and show results of those commands?
That's generally not how consoles work. You could however choose some sort of workarounds as suggested in the answers to this duplicate question: Multithreading: simultaneous console in- and output.
It is suggested there to override contents of the window and/or maintain the input by taking it character by character and redisplaying it.
You could also consider writing a simple non-console application (WinForms, WPF, UWP, etc.) to display a console-like output and input box.
Cheers
Related
This question already has answers here:
Run interactive command line exe using c#
(3 answers)
Closed 6 years ago.
I can't seem to find a possible solution for entering 1 line of "command" into a CMD window. I searched the MSDN and asked google and they only found me solutions to enter text into a textfile, but that's not the same I guess.
Thank you in advance!
You're going to have to start the Minecraft service process from your .NET application. Whatever you've got now in the batch file you're using, you can duplicate that in the Process start code in C#, or you can just have your C# code run the batch file.
If you want a config file providing startup parameters, you could put that stuff in app.config and have your application give them to the Minecraft server process on startup.
Once you've got the process started, your application can keep the Process object and send repeated commands to its standard input stream, as outlined in this answer.
System.Diagnostics.Process.Start("CMD.exe", [your command]);
This question already has answers here:
Why do UI Controls in WPF have Thread Affinity?
(2 answers)
Can you access UI elements from another thread? (get not set)
(4 answers)
Closed 9 years ago.
I am in learning multithreading (and related stuff like concurrency, TPL - in .NET, Windows) and hope that thу answers to this question would significantly reduce the amount of my doubts.
Why WPF UI requires output (from multiple threads) through the Dispatcher while the console does not?
I hope that this explanation will be a little more detailed then the overused and underdefined in MSDN docs phrase that Console class is thread-safe (or better to avoid the use of ambiguous terms at all).
Update:
Thanks to Justin Pihony's comment, sub-question:
Why reading from WPF UI is not possible without a Dispatcher object while Windows Forms permit both reading and writing without Invoke/BeginInvoke?
Why (or how) does reading compromise thread-safedty of WPF UI?
I am trying to disambiguate for me the phrase from Parallel Programming in .NET Framework 4: Getting Started :
"I didn’t have problems with the console application because the
Console class is thread safe. But in WPF, UI components can be safely
accessed only by a dedicated UI thread"
Proposed topics for reading the answers:
Why does Console.ReadKey() block output of Console.WriteLine called in another thread?
Can you access UI elements from another thread? (get not set)
Why do UI Controls in WPF have Thread Affinity?
Calling Console.WriteLine from multiple threads
WPF/WinForm create and use window, which has affinity on single threading.
console don't use window, it just output/reply string.
it's "by design of window development".
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a way to overlay an application over a full-screened program?
Is it possible in C# to inject a text to process (like fraps for example), but without using any .dll injections?
Thanks in advance for responses.
#update
"A text" means some fast refreshing labels or something, which will show informations e.g.:
Name:Test
Pos: x=123,y=456,z=0
Level: Unknown
Something.....
You can use automation to send keyboard actions and suchlike to another program. Otherwise if there is no exposed API then things look bleak. See this question for an overview on the methods you use to send keystrokes.
EDIT: What you're asking for is not injection, it's an overlay. What you're looking to do is take control of the display buffer so that your overlay always has a higher z-index than whatever is being rendered. Take a look at this answer
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
single instance and notify in system tray
I am trying to implement a program in C#.NET. My program uses the notification icon. I have made my program a single instance program using the class singleinstance.cs from codeproject.
Now, what I am trying to do is, if I close the main window and then if I run the application again, it should open the main window of the already running program instance in the system tray.
I have googled a lot over this but didn't find something useful for me.
You need to maximize the window of an existing process, correct?
Here is an example of another question: Maximize another process' Window in .NET
To note, in the future, this is a borderline duplicate question, in my opinion. You could have used the search box in the top right of this page to find this answer on your own.
This question already has answers here:
Advanced Console IO in .NET
(4 answers)
Closed 4 years ago.
I am trying to create points inside a console window based on a 80x49 grid. But I am getting stuck on the basic idea.
My thought was to first of all print out spaces on the entire page so that later, when my method Draw() is called, it replaces a space with a character of choosing.
Keep in mind that the application should be able to print out new points on the same "canvas" again and again. Say that we first print a * at 4,5 and then a * at 4,7 . I am guessing SetCursorPos wouldn't work?
Yes, Console.SetCursorPosition is what you should use.
see advanced console io in .net