Last active
December 2, 2015 17:22
-
-
Save robertstefan/920c72ca67ca52c0cc91 to your computer and use it in GitHub Desktop.
C# ConsoleSpinner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var spin = new ConsoleSpinner(); | |
Console.Write("Working...."); | |
while (true) | |
{ | |
spin.Turn(); | |
} | |
/* | |
* One-line progress indicator | |
* | |
for(int i = 0; i < 100; ++i) | |
{ | |
Console.Write("\r{0}% ", i); | |
} | |
*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsoleSpinner | |
{ | |
int counter; | |
public void Turn() | |
{ | |
counter++; | |
switch (counter % 4) | |
{ | |
case 0: Console.Write("/"); counter = 0; break; | |
case 1: Console.Write("-"); break; | |
case 2: Console.Write("\\"); break; | |
case 3: Console.Write("|"); break; | |
} | |
Thread.Sleep(100); | |
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment