Doron Muzar
Doron Muzar

Reputation: 443

How do i show/display a counter count back from 20 minutes to 0?

My program finished the operation from now to next update time. i want to show the user a counter clock count in the format: 00:00:00 Then 00:20:00 and count 20 minutes back.

This is the code where the operation is finished and timer1 should start:

private void DownloadCompletedCallback(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                //... download cancelled...
            }
            else if (e.Error != null)
            {
                //... download failed...
                Logger.Write("Error: " + e.Error);
            }
            ActiveDownloadJob adJob = e.UserState as ActiveDownloadJob;
            ProgressBar pb = (adJob != null) ? adJob.ProgressBar : null;

            lock (_downloadQueue)
            {
                if (_downloadQueue.Count == 0)
                {
                    if (pb != null)
                    {
                        pb.Tag = null;
                        timer2.Stop();
                        label8.ForeColor = Color.Green;
                        label8.Text = "Process Finished";
                        label7.Visible = true;

Timer3 tick event if empty now but i think there i should make and display the counter back.

Upvotes: 0

Views: 186

Answers (1)

Noctis
Noctis

Reputation: 11763

Set the execution time, 20 minutes into the future

var rut_at = DateTime.Now().AddMinutes(20);

And bind or refresh every second a variable called timeLeft that is defined as

var timeLeft = run_at - DateTime.Now();

Upvotes: 2

Related Questions