Results 1 to 2 of 2

Thread: Backgroundworker + progress bar

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Backgroundworker + progress bar

    What I am trying to figure out is how to display a progress bar when im performing a large task. This task will consist of reading records from a database, writing them to a text file, manipulating the data to write to a database and then present them on the screen. There can be several thousand records that I have to manipulate. I am having trouble getting a progressbar to accuratly display the progress. My problem seems to be that since i cant determine exactly how many records and how much time it will take that I cant accuratly update the progressbar. Any help is appreciated. Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Backgroundworker + progress bar

    If you don't know how many records there are to begin with then it's simply not possible to display an absolute progress. You could perform two queries, the first being intended to get the number of records that the second will return, e.g.
    Code:
    Query 1: SELECT COUNT(*) FROM MyTable WHERE ID > 100
    Query 2: SELECT * FROM MyTable WHERE ID > 100
    Once you've performed the first query then you know how many records the second query will return. The problem with that is you will slow down the overall operation by performing the first query, particularly if it is very complex. You could test this to see how deterimental to performance it actually is. If it does have a significant effect then your only realistic course of action is to display a ProgressBar where the Style is set to Marquee, which simply indicates that SOMETHING is happening, as opposed to how far it has progressed.

    Alternatively you could simply allocated a set proportion of the overall progress to the query and use a DataAdapter to get all the data in one go. You then know how many records there are so you can display an actual progress for writing the data using the remainder of the total progress. You'll probably find that this will incur a performance penalty too though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width