is vbs event handling actually multi-threading?

Posted on 2005-05-07
Last Modified: 2010-05-02
if i've got an application that is just a loop with a counter in it - adn that loop updates a label on a form with that counter but every 100 iterations it raises an event for which the event handler contains quite complex code - how does vb handle this?

i.e. - will my loop continue to run while the event is handled?  or can vb only do one or the other?

i.e. - i need my loop to keep going (obviously in my applciation its not just incrementing a counter - its doing database work) - but i also need the events that get raised to be handled at the same time.  Can i do that?
Question by:kenshaw
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Instead of using a loop use a timer.  In the "complex operation" code that gets called every 100 iterations, be sure place DoEvents in any loops to allow the timer code to fire and be processed.
    LVL 4

    Author Comment

    well... i sort of wrote it like that for a reason.  i'm maintaining code and i can't get rid of the loop.  the loop code has about 200 lines of code in it - and it needs to be a loop b/c its processing a recordset.

    does anyone know the answer to the question?
    LVL 26

    Expert Comment

    then as idle_mind said, use doevents
    LVL 4

    Author Comment

    I don't think anyone really answered this question.  I think the moderator should delete it.
    LVL 1

    Accepted Solution

    vb event handling is NOT multi-threading nor asynchronous.  When the event gets fired, VB will rush off to execute code for the event, not continuing to do whatever you do in your loop.  Also, once the code for the event completes execution, vb will not then "come back" to executing the code in your loop.  Of course, this is all based on the assumption that you have a doevents inside your loop, so that the event code will get started to begin with.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now