Progressbar 's progress

OmkarHcl 206 Reputation points
2023-07-16T08:37:28.5366667+00:00

Hi , my current question is link to my previous question that i asked in https://learn.microsoft.com/en-us/answers/questions/1331115/multiple-tables-in-dataset
. I have a progressbar in my windows form .How can i use the time taken by the system to perform all the operations and show it in the progressbar .

Developer technologies Windows Forms
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-07-17T03:14:39.46+00:00

    Hi @OmkarHcl , Welcome to Microsoft Q&A.

    I looked at the example you provided and it looks like you want to use toolStripProgressBar1 to complete the progress bar. You can simulate a progress bar moving. Use the PerformStep and timer controls that come with toolStripProgressBar1 to move the progress bar. Set an approximate long time, open the timer control at the beginning of the query, make the progress bar 100 at the end, and close the timer control.

    private void timer1_Tick(object sender, EventArgs e)
    {
         if (toolStripProgressBar1. Value < toolStripProgressBar1. Maximum)
         {
             this.toolStripProgressBar1.PerformStep();
         }
    }
    
    private async void button1_Click(object sender, EventArgs e)
    {
         timer1. Start();
         timer1. Interval = 1000;
         toolStripProgressBar1. Step = 2;
         // Simulate a long query process
         int totalRows = 100; // Suppose there are 100 rows in total in the query result
         int rowsProcessed = 0;
         await Task. Run(() =>
         {
             while (rowsProcessed < totalRows)
             {
                 Thread.Sleep(500); // For demonstration purposes, use Thread.Sleep to simulate delays during queries
                 rowsProcessed += 10;
    
             }
         });
         toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
         timer1. Stop();
    }
    

    7_17_1

    Set the appropriate step and interval according to your own needs.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.