On Sun, Feb 8, 2009 at 2:02 AM, Joe C. <[email protected]> wrote: > > thank you for reading. > > i have a windows application, a tool built to take large text files > (containing data) to import into a sql server table. > > the text files contain more than 300,000 lines of data at a time. > > vb.net code in the windows application reads each line, parses, then > inserts into the database table. > > on the form i have set a label to show the progress of the data > migration, and a progress bar reflecting percentage finished. > > problem is, during the loop, if the form is moved or focus taken away > from the form, the form itself freezes. the progress bar no longer > moves forward, and label also stops showing any updates. > > but the background process, of reading the text line, then inserting > into sql, still runs and eventually the entire process will finish. > > so my problem is a cosmetic one, i would like to form to continue > updating the information while the long running loop is completed. > > any help would be greatly appreciated.
A C pointed out, you can do this with threads (the best approach) or you can have the loop yield ever so many iterations and call Application.DoEvents(); // example int counter = 0; //in your loop increment the counter by 1 and check with the modulus operator for a certain number of iterations... counter++; if (counter % 200) Application.DoEvents(); This will allow other tasks to run suck as the form being redrawn, progressbar to update, etc.
