I’m using System.Windows.Forms.Timer to display a transfer file update progress(timeleft, speed ..etc)
and I also use backgroundworker to send the file
backgroundWorker1_DoWorkcallstimer1.Start();backgroundWorker1_RunWorkerCompletedcallstimer1.Stop();
It works fine only in the first call for timer1.Strat, but when it called again after timer1.Stop(). It doesn’t work.
timer1.Enabled = True;
timer1.Interval = 1000;
private void timer1_Tick(object sender, EventArgs e)
{
long speed = sumAll - prevSum;
prevSum = sumAll;
labelSpeed.Text = CnvrtUnit(speed) + "/S";
if (speed > 0)
{
totalSeconds++;
labelTime.Text = FormatRemainingText(TimeSpan.FromSeconds((sizeAll - sumAll) / speed));
labelTotalTime.Text = FormatRemainingText(TimeSpan.FromSeconds(totalSeconds));
}
}
What’s wrong with it and how do I fix it?
I’ve figured it out, I use
System.Timers.Timerinstead ofSystem.Windows.Forms.TimerIn class constructor I added:
Now it works every time I call
timer1.Start(), no need to “AutoReset”.