Anyone know a better way to suspend execution of VB code until an activex control responds and the event is handled other than using a loop with a doevents statement in it. Such a loop seems to be slowing my application significantly. Thanks.
I'm not sure I understand your requirement, but we'll see.
You could try tying your DoEvents to a timer rather than a loop. That way you can control the number of times per second DoEvents gets executed.
This thread thread222-1285729 will give you a basic technique that might work better. I'd use the IsProcessRunning part of this along with a Timer function. If you want to explore this idea further, doing a search in the VB5/6 forum for "IsProcessRunning" will give more examples from Hypetia.
My guess would be that this user is trying to force logic on a VB form to run as straight-line code instead of programming against the form's event model. Thus use of a Timer's events would probably defeat his purpose.
While there are exceptions to every rule, the basic principal I follow with DoEvents() is don't. The major exception is to allow UI updates to take place during lengthy processing within an event handler: things like progress bar updates, status line message display, and command button enable/disable or caption changes. There are other exceptions too of course but most of them occur within the logic of a UserControl or Class that is processing local events and wants to raise an event to its container and allow it to be handled right away.
Using DoEvents() within an event handler always presents the potential of unanticpated re-entrancy. I see this most often with code handling Winsock control events, where it can lead to problems ranging from received data fragments being processed out of sequence to stack overflows.
Well, maybe so, in which case my response wouldn't make a lot of sense. However, I was thinking that the OP was talking about a control running asynchronously in a separate process.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.