0

I have a console application which does some process and shows some success and failure messages at the end with Console.Readline();

Once the user see those messages, lets say in 10 seconds I want to close the console window automatically but that does not happen.

I tried return, Environemnt.Exit(0) but console does not close.

I don't the use to press some key, is there any way to close the console window automatically.

It's a .NET 4.0 based console application

msbyuva
  • 3,467
  • 13
  • 63
  • 87
  • are you using ReadLine just for stopping purposes, or do you really need user input? – d.moncada May 15 '14 at 18:09
  • I am using console.readline() to display the status messages from Console.Writeline() --- readline purpose is only to display those messages on the console – msbyuva May 15 '14 at 18:12
  • Are you running your console application by double-clicking the icon, or by invoking it textually from an already open console window? – O. R. Mapper May 15 '14 at 18:12
  • its a scheduled task...runs automatically at scheduled time from task scheduler – msbyuva May 15 '14 at 18:13
  • I don't quite get why are you using Console.ReadLine(), could you explain please? – Asad Ali May 15 '14 at 18:33
  • 1
    In summary you are using Console.ReadLine() but you don't want the user to have to press some key? ConsoleReadLine() does not display messages. – paparazzo May 15 '14 at 18:38
  • [See this](http://stackoverflow.com/questions/57615/how-to-add-a-timeout-to-console-readline). That should do what you're seeking. – Asad Ali May 15 '14 at 18:50
  • 1
    If you have a set interval that you want to wait, why even call Console.Readline()? Why not just Thread.Sleep(10000)? – J.Wells May 15 '14 at 19:36
  • @J.Wells, thank you.. I simply used thread.sleep... it solved my purpose.!! – msbyuva May 15 '14 at 20:26
  • Np! I'll post as an answer that you can accept. – J.Wells May 15 '14 at 20:28

1 Answers1

1

Calling Thread.Sleep(10000); will delay execution of the current thread for 10 seconds, then continue, eliminating the need to call Console.Readline().

J.Wells
  • 1,749
  • 12
  • 13