Skip to content

Commit

Permalink
Fix Run method to use while loop instead of stupid recursion.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivSolutions committed Sep 9, 2014
1 parent 93ff80e commit f5a7605
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions ConsoleApplicationBase/Program.cs
Expand Up @@ -47,32 +47,28 @@ static void Main(string[] args)

static void Run()
{
// Get input from the user:
var consoleInput = ReadFromConsole();
if(string.IsNullOrWhiteSpace(consoleInput))
{
// Nothing was provided - start over:
Run();
}
try
{
// Create a ConsoleCommand instance:
var cmd = new ConsoleCommand(consoleInput);
while (true)
{
var consoleInput = ReadFromConsole();
if (string.IsNullOrWhiteSpace(consoleInput)) continue;

// Execute the command:
string result = Execute(cmd);
try
{
// Create a ConsoleCommand instance:
var cmd = new ConsoleCommand(consoleInput);

// Write out the result:
WriteToConsole(result);
}
catch (Exception ex)
{
// OOPS! Something went wrong - Write out the problem:
WriteToConsole(ex.Message);
}
// Execute the command:
string result = Execute(cmd);

// Always return to Run():
Run();
// Write out the result:
WriteToConsole(result);
}
catch (Exception ex)
{
// OOPS! Something went wrong - Write out the problem:
WriteToConsole(ex.Message);
}
}
}


Expand Down

0 comments on commit f5a7605

Please sign in to comment.