using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace WLanStatictisc
{
    class MyTimer
    {
        public static event EventHandler isTime;
        static private Thread timer;  
        public static int period {set; get;}
        private static bool timerStoped = true;

        public static void itIsTimeEventTrigger()
        {
            while (true)
            {
                Thread.Sleep(period);
                if(isTime!=null)isTime(null, new EventArgs());  
            }
        }
        public static void stopTimer()
        {
            if (timerStoped == false)
            {
                timer.Abort();
                timerStoped = true;
            }
        }

        public static void startTimer()
        {
            if (timerStoped == true)
            {
                try
                {
                    timer = new Thread(itIsTimeEventTrigger);
                    period = 2000;
                    timer.Start();
                    timerStoped = false;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message.ToString());
                }
            }
        }
    }
}
