I have the follwing code that provides an auto refresh feature to a WCF Console Hosted Application.
When the Console.ReadKey accepts an invalid character, it restarts the ReadKey method. If the user mashes the keyboard long enough on this code it will go into a StackOverflowException.
Does anyone have a way to re-write this code so that it doesn't cause the stack to blow?
[STAThread]
static void Main(string[] args)
{
bool restart = true;
while(restart)
{
using (var myWcfHost = new MyWcfHost())
{
myWcfHost.start();
Console.WriteLine("Press Enter to quit or Ctrl+R to restart");
restart = WaitForRestart();
}
}
}
private static bool WaitForRestart()
{
// clear users input
Console.CursorLeft = 0;
Console.Write(' ');
Console.CursorLeft = 0;
// read users input
var key = Console.ReadKey();
if ((key.Modifiers & ConsoleModifiers.Control) != 0
&& key.Key == ConsoleKey.R)
{
// refersh the settings
ConfigurationManager.RefreshSection("appSettings");
return true;
}
if (key.Key == ConsoleKey.Enter || key.Key == ConsoleKey.Escape)
{
return false;
}
return WaitForRestart();
}