Results 1 to 6 of 6

Thread: [RESOLVED] Displaying Progress

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Resolved [RESOLVED] Displaying Progress

    I'm using Visual Studio 2003, and I'm coding in Visual Basic .NET. Also I'm using SQL Express 2005, though I don't think that will apply here.

    I have created a program that uses httpWebRequests to go through thousands of web pages via an increasing integer and parse out results and insert them into a database. My problem is that this can take about an hour and I have no way of seeing the progress. I put a label in the upper right corner of my form that is supposed to show the current integer being used for the webrequest, but when I run the process the window basically freezes up. If I minimize it and then try to bring it back up none of the form components will show up until it's complete, just the default window color with transparency where the buttons and datagrids would be. I know the label is working because after the process has completed the correct number is displayed.

    There has to be some way to have the program show my progress without freezing up. Maybe a status bar or something? Anything that will show me the progress is suitable, whatever uses the least resources would be the most desireable.

    Thanks,
    JSand4325
    Last edited by JSand4325; Apr 26th, 2006 at 09:50 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] Displaying Progress

    in your loop that you use to loop through these 1000s of pages, add Application.Doevents, and that line of code will allow your GUI to repaint itself when a tight processing loop is going on that makes your app appear frozen.

    Another solution would be to use threads, but the easiest implementation, is to use Application.DoEvents

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] Displaying Progress

    Thanks alot! For now I'll definitely just go with Application.DoEvents. I've searched on MSDN for threading and I've found the perfect article, but it's for C#. Do you happen to know of any good articles on threading for VB.NET?

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] Displaying Progress

    in the 101 VB.NET examples sticky at the top of this forum, there is an example on threading which should help you to see how it works..

    as far as articles, just google vb.net threading and you should turn up some results..

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,440

    Re: [02/03] Displaying Progress

    Just make sure that you do not call Application.DoEvents every iteration of the loop unless each iteration takes a long time. If you're using a loop that has a lot of iterations but each iteration takes a short time then calling DoEvents every iteration will actually slow things down, as it is a relatively expensive operation. You would want to call DoEvents as infrequently as possible to make your app appear responsive. This may be every 100 iterations, or every 500 or every 1000. To process pending events every 100 iterations of a loop you would do something like this:
    VB Code:
    1. For i As Integer = 0 To someReallyBigNumber Step 1
    2.     'Do something here.
    3.  
    4.     If i Mod 100 = 0 Then
    5.         Application.DoEvents()
    6.     End If
    7. Next i
    Also, the Articles -> Advanced .NET link in my signature has a section on Managed Threading that will tell you everything you need to know on the subject.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] Displaying Progress

    thanks alot for the info

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