Exemplo n.º 1
0
 public NetStatus(int averageTime)
 {
     this.averageTime = averageTime;
     speedList        = new List <SpeedUnit>();
     for (int i = 0; i < averageTime; i++)
     {
         SpeedUnit unit = new SpeedUnit();
         if (i == 0)
         {
             currentUnit = unit;
         }
         speedList.Add(unit);
     }
     mainThread = new Thread(() =>
     {
         long lastTime = DateTime.Now.Millisecond;
         while (true)
         {
             if (Math.Abs(System.DateTime.Now.Millisecond - lastTime) > 1000)
             {
                 lastTime = System.DateTime.Now.Millisecond;
                 calcuSpeed();
             }
             try
             {
                 Thread.Sleep(100);
             }
             catch
             {
                 break;
             }
         }
     });
     mainThread.Start();
 }
Exemplo n.º 2
0
        void calcuSpeed()
        {
            int ds = 0, us = 0;

            foreach (SpeedUnit unit in speedList)
            {
                ds += unit.downSum;
                us += unit.upSum;
            }
            upSpeed   = (int)((float)us / speedList.Count);
            downSpeed = (int)(float)ds / speedList.Count;

            speedList.RemoveAt(0);
            SpeedUnit speedunit = new SpeedUnit();

            currentUnit = speedunit;
            speedList.Add(speedunit);
        }