locked
how to link Progress bar with StopWatch

    Question

  • hi

    i have a progress bar in my app.i want link value and max value to stopwatch.

    that when watch is active my progress bar change value.

    my code is : 

    allTime=1000*5 //for example

    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    Thread.Sleep(allTime);
                    TimeSpan ts = sw.Elapsed;
                    ProgressBar.Maximum =allTime;
                    ProgressBar.Value =ts.Milliseconds;
                    sw.Stop();

    this code not work.

    please help me about this.

    tank you


    Amir Ameri

    Thursday, January 08, 2015 1:40 PM

Answers

  • here is a complete sample i made for you:

    http://1drv.ms/1tPCSRA


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by AMIR ameri Friday, January 09, 2015 9:12 AM
    Friday, January 09, 2015 7:39 AM
  • Its the max value. You can configure the interval at the dispatchtimer

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by AMIR ameri Friday, January 09, 2015 9:12 AM
    Friday, January 09, 2015 8:03 AM

All replies

  • you going to need a timer which pulls out the Stopwatch and set it in the progrssbar.

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, January 08, 2015 1:49 PM
  • i change my code :

    Stopwatch timer = new System.Diagnostics.Stopwatch();
                timer.Start();

                for (int loop = 0; loop < 5; loop++)
                {
                    Thread.Sleep(500);
                    label1.Text +=1;
                }
                timer.Stop();

     its work true but label text dont added every 500 interval.

    but type 11111 at last.

    i want step by step show change text value.


    Amir Ameri

    Thursday, January 08, 2015 4:52 PM
  • here is a complete sample i made for you:

    http://1drv.ms/1tPCSRA


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by AMIR ameri Friday, January 09, 2015 9:12 AM
    Friday, January 09, 2015 7:39 AM
  • Tank you very much Dave

    its very useful for me.

    why this code does not work:

                 ProgressBar.Maximum =count;

                    Stopwatch sw = new Stopwatch();

                    sw.Start();
                    for (int i = 1; i <= count; i++)
                    {
                       Thread.Sleep(500);
                       ProgressBar.Value += 1;
                     }
                   sw.Stop();


    Amir Ameri



    • Edited by AMIR ameri Friday, January 09, 2015 8:35 AM
    Friday, January 09, 2015 8:00 AM
  • Its the max value. You can configure the interval at the dispatchtimer

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by AMIR ameri Friday, January 09, 2015 9:12 AM
    Friday, January 09, 2015 8:03 AM
  • tank you.

    Amir Ameri

    Friday, January 09, 2015 9:12 AM