Ancora un pò svogliato nel provare a fare post - anche solo lontamamente - minimamente impegnati... ecco qui a postare - per la categoria "idee regalo" - il "ConsoleSlideShow" per ingannare i tempi di attesa delle applicazioni console...
class Program
{
static void Main(string[] args)
{
ConsoleSlideShow slideShow = new ConsoleSlideShow(
@"\ Loading",
"| Loading .",
"/ Loading ..",
"- Loading ...");
slideShow.SlidingTime = 200;
slideShow.Start();
Thread.Sleep(10000);
slideShow.Stop();
Console.Write("Completed successfully");
Console.ReadLine();
}
}
class ConsoleSlideShow
{
string[] steps;
bool slideOn;
Thread slideThreadRef;
public ConsoleSlideShow(params string[] steps)
{
this.steps = steps;
slideOn = false;
slidingTime = 100;
}
private int slidingTime;
public int SlidingTime
{
get { return slidingTime; }
set { slidingTime = value; }
}
public void Stop()
{
if (!slideOn)
throw new InvalidOperationException("Slide show was not started.");
slideOn = false;
slideThreadRef.Join();
}
public void Start()
{
if (slideOn)
throw new InvalidOperationException("Slide show was already started.");
slideOn = true;
slideThreadRef = new Thread(new ThreadStart(SlideShow));
slideThreadRef.Start();
}
void SlideShow()
{
while (slideOn)
{
foreach (string step in steps)
{
Console.Write(step);
Thread.Sleep(slidingTime);
Console.Write('\r');
Console.Write(new string('\x20', step.Length));
Console.Write('\r');
}
}
}
}
posted @ martedì 5 settembre 2006 16:52