Just that. I found a similar question here : c# console, Console.Clear problem
but that didn't answer the question.
UPDATES :
Console.Clear() throws : IOException (The handle is invalid)
The app is a WPF app. Writing to the console however is no problem at all, nor is reading from.
What is Clrscr() in C? clrscr() function clears the screen and moves the cursor to the upper-left-hand corner of the screen. It is defined in conio. h header file. This function is optional.
A common way to do that is to use the `clear` command, or its keyboard shortcut CTRL+L.
clear() The console. clear() method clears the console if the console allows it.
Console.Clear()
works in a console application.
When Calling Console.Clear()
in a ASP.NET web site project or in a windows forms application, then you'll get the IOException.
What kind of application do you have?
Update:
I'm not sure if this will help, but as you can read in this forum thread, Console.Clear()
throws an IOException if the console output is being redirected. Maybe this is the case for WPF applications? The article describes how to check whether the console is being redirected.
Try
Console.Clear();
EDIT
Are you trying this method on a non-Console application? If so that would explain the error. Other types of applications, ASP.Net projects, WinForms, etc ... don't actually create a console for writing. So the Clear has nothing to operate on and throws an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With