ConsoleSlideShow, la barra di attesa per le applicazioni console

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

Print
Comments have been closed on this topic.
«agosto»
domlunmarmergiovensab
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910