Commandline UI while waiting for a thread to finish

Published Wed, Mar 30 2005 23:30 | girishb
Here is a simple way to show something is happening on a client end background thread (which I am sure you have seen it in Linux and other command UIs)..
//assuming async is IAsyncResult
		char nextChar = '/';
		while (!async.AsyncWaitHandle.WaitOne(100,true)) {
			if (nextChar == '-'){
				nextChar = '\\';
			}else if (nextChar == '\\') {
				nextChar = '|';
			}else if (nextChar == '|'){
				nextChar = '/';
			}else if (nextChar == '/'){
				nextChar = '-';
			}
			i++;
			Console.Write("\b{0}",nextChar);
		}
This lets you show that simple rotating char on the command line. I have it here so I can paste this for my tool apps.