예제 #1
0
 void t5can_onWriteProgress(object sender, WriteProgressEventArgs e)
 {
     if (progressBar1.Value != e.Percentage)
     {
         progressBar1.Value = e.Percentage;
         if (e.Percentage > 99)
         {
             progressBar1.Value = 0;
         }
         Application.DoEvents();
     }
 }
예제 #2
0
 void t5can_onBytesTransmitted(object sender, WriteProgressEventArgs e)
 {
     if (stopwatch.ElapsedMilliseconds > 0)
     {
         int bytespersecond = (1000 * e.Percentage) / (int)stopwatch.ElapsedMilliseconds;
         label2.Text = "Transmission speed: " + bytespersecond.ToString() + " B/s";
         label1.Text = "Transferred: " + e.Percentage.ToString() + " Bytes";
         // calculate ETA
         // total amount to transfer = 100/percentage * bytetransferred
         if (progressBar1.Value > 0)
         {
             if (progressBar1.Value != last_progress)
             {
                 int totalbytes = (int)((float)((float)100 / (float)progressBar1.Value) * (float)e.Percentage);
                 // time remaining = (totalbytes - bytestranferred)/bytespersecond
                 int secondsleft = (totalbytes - e.Percentage) / bytespersecond;
                 int minutes = secondsleft / 60;
                 int seconds = secondsleft - (minutes * 60);
                 label3.Text = "Remaining time: " + minutes.ToString("D2") + ":" + seconds.ToString("D2");
                 last_progress = progressBar1.Value;
                 //Console.WriteLine("total bytes: " + totalbytes.ToString() + " seconds left: " + secondsleft.ToString() + " bytestransferred: :" + e.Percentage.ToString() + " bps: " + bytespersecond.ToString());
                 //if ((delaycount++ % 10) == 0)
                 {
                     Application.DoEvents();
                 }
             }
             else if ((delaycount++ % 10) == 0)
             {
                 int totalbytes = (int)((float)((float)100 / (float)progressBar1.Value) * (float)e.Percentage);
                 // time remaining = (totalbytes - bytestranferred)/bytespersecond
                 int secondsleft = (totalbytes - e.Percentage) / bytespersecond;
                 int minutes = secondsleft / 60;
                 int seconds = secondsleft - (minutes * 60);
                 label3.Text = "Remaining time: " + minutes.ToString("D2") + ":" + seconds.ToString("D2");
                 last_progress = progressBar1.Value;
                 //Console.WriteLine("total bytes: " + totalbytes.ToString() + " seconds left: " + secondsleft.ToString() + " bytestransferred: :" + e.Percentage.ToString() + " bps: " + bytespersecond.ToString());
                 Application.DoEvents();
             }
         }
     }
 }