Results 1 to 5 of 5

Thread: Why is DoEvents bad?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    Phoenix
    Posts
    87

    Unhappy

    I've seen on these boards a lot that people have been criticized for using DoEvents in a loop. Why is this bad? To me it sounds like a good idea to give control back to Windows temporarily to let it catch up on what it needs to do.

    Also, I have a loop in one of my programs that updates a progress bar. Well the progress bar won't graphically show the updates unless I have a doEvents statement in there.
    Is there another way to get it to graphically update?

    Many thanks!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Doevents actually only concerns your program not any others. The bad thing about doevents is that it hangs up your app if called after all forms are unloaded.

    Doevents updates the graph? yeah that because a WM_Paint message is queing for being processed by your app
    Well a good way to avoid probs with doevents is to check if there are any forms left.
    Code:
    'for a loop
    Do while forms.count
    doevents
    'code
    loop
    'and another one
    Do
    'code
    doevents
    Loop while forms.count
    'and other frequently used code
    If forms.count then doevents
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    It's kinda bad to use doevents to redraw the progress bar, this code is faster:
    Code:
    ProgressBar.Refresh
    The code is faster then doevents, because doevents gives every program a chance to do something.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Not really, doevents gives only your program a chance to handle it's message queue, that's if the progressbar is the only thing to update, then it will update without any other process being executed
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    Phoenix
    Posts
    87

    woo

    thanks a bunch guys

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