PC Review


Reply
Thread Tools Rate Thread

2nd form's DoEvents pauses 1st form's DoEvents

 
 
Albert
Guest
Posts: n/a
 
      23rd Feb 2004
Hello,

I have a form do some operations in looping. Due to it takes a long time, I
insert DoEvents() in this loop. I have another form do some looping and it
includes DoEvents() also. Both form possible to run at the same time.
Problem I found is whenever second form (any form) is run ,if first form is
in looping, second form DoEvents() will pause first form looping. When
second form quit looping, First form continue looping.

How to solve this ?

TIA,
Albert


 
Reply With Quote
 
 
 
 
Graham R Seach
Guest
Posts: n/a
 
      23rd Feb 2004
Albert,

You can't stop it from happening. The behaviour you experience is by design.

Access does not spawn a new thread for every module, so all code (with the
exception of asynchronous database operations) will run procedurally (one
after the other). If your main form calls a procedure in a subform or other
module, thereby passing control to it, that code will execute until it has
finished, after which it passes control back to the procedure that called
it.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

"Albert" <(E-Mail Removed)> wrote in message
news:eZJ%23UBd%(E-Mail Removed)...
> Hello,
>
> I have a form do some operations in looping. Due to it takes a long time,

I
> insert DoEvents() in this loop. I have another form do some looping and it
> includes DoEvents() also. Both form possible to run at the same time.
> Problem I found is whenever second form (any form) is run ,if first form

is
> in looping, second form DoEvents() will pause first form looping. When
> second form quit looping, First form continue looping.
>
> How to solve this ?
>
> TIA,
> Albert
>
>



 
Reply With Quote
 
Albert
Guest
Posts: n/a
 
      23rd Feb 2004
Thanks for your reply.

But my case, 1st form does not call 2nd form. Both form can be opened
directly by user. Is this multi-thread ?

Thanks,
Albert

"Graham R Seach" <(E-Mail Removed)> wrote in message
news:Ogo9xEd#(E-Mail Removed)...
> Albert,
>
> You can't stop it from happening. The behaviour you experience is by

design.
>
> Access does not spawn a new thread for every module, so all code (with the
> exception of asynchronous database operations) will run procedurally (one
> after the other). If your main form calls a procedure in a subform or

other
> module, thereby passing control to it, that code will execute until it has
> finished, after which it passes control back to the procedure that called
> it.
>
> Regards,
> Graham R Seach
> Microsoft Access MVP
> Sydney, Australia
>
> "Albert" <(E-Mail Removed)> wrote in message
> news:eZJ%23UBd%(E-Mail Removed)...
> > Hello,
> >
> > I have a form do some operations in looping. Due to it takes a long

time,
> I
> > insert DoEvents() in this loop. I have another form do some looping and

it
> > includes DoEvents() also. Both form possible to run at the same time.
> > Problem I found is whenever second form (any form) is run ,if first form

> is
> > in looping, second form DoEvents() will pause first form looping. When
> > second form quit looping, First form continue looping.
> >
> > How to solve this ?
> >
> > TIA,
> > Albert
> >
> >

>
>



 
Reply With Quote
 
Graham R Seach
Guest
Posts: n/a
 
      23rd Feb 2004
Albert,

To illustrate how things work in Access, follow this procedure:

1. Create two identical forms, Form-A and Form-B.

2. Put a command button and a textbox (named Text1) on each form.

3. Add the following code to the Click event of the button on each form.

Dim ctr As Long

Debug.Print "Form-A start"
For ctr = 1 To 100000
Me.Text1 = ctr
DoEvents
Next ctr

Debug.Print "Form-B finish"

4. Change the Debug.Print statements on Form-B as follows:
Debug.Print "Form-B start"
Debug.Print "Form-B finish"

5. Save the forms, then open both of them.

6. As quickly as you can, click the button on both forms.

You'll notice that Form-A's code starts to execute until you click the
button on Form-B. This is because Form-B's Click event generates an
Interrupt, which passes immediate control to Form-B. Form-B's code will
continue to execute until it either naturally completes, or is interrupted
by a system event (like another Click event) elsewhere, after which it will
return control to Form-A.

If you check the Immediate window, you'll see the following:
Form-A start
Form-B start
Form-B end
Form-A end

So you see that, ignoring the interrupts themselves, there is no threading
going on here. Code is executing procedurally.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

"Albert" <(E-Mail Removed)> wrote in message
news:e9fUird%(E-Mail Removed)...
> Thanks for your reply.
>
> But my case, 1st form does not call 2nd form. Both form can be opened
> directly by user. Is this multi-thread ?
>
> Thanks,
> Albert
>
> "Graham R Seach" <(E-Mail Removed)> wrote in message
> news:Ogo9xEd#(E-Mail Removed)...
> > Albert,
> >
> > You can't stop it from happening. The behaviour you experience is by

> design.
> >
> > Access does not spawn a new thread for every module, so all code (with

the
> > exception of asynchronous database operations) will run procedurally

(one
> > after the other). If your main form calls a procedure in a subform or

> other
> > module, thereby passing control to it, that code will execute until it

has
> > finished, after which it passes control back to the procedure that

called
> > it.
> >
> > Regards,
> > Graham R Seach
> > Microsoft Access MVP
> > Sydney, Australia
> >
> > "Albert" <(E-Mail Removed)> wrote in message
> > news:eZJ%23UBd%(E-Mail Removed)...
> > > Hello,
> > >
> > > I have a form do some operations in looping. Due to it takes a long

> time,
> > I
> > > insert DoEvents() in this loop. I have another form do some looping

and
> it
> > > includes DoEvents() also. Both form possible to run at the same time.
> > > Problem I found is whenever second form (any form) is run ,if first

form
> > is
> > > in looping, second form DoEvents() will pause first form looping. When
> > > second form quit looping, First form continue looping.
> > >
> > > How to solve this ?
> > >
> > > TIA,
> > > Albert
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with DoEvents to show progress form, please? Ed from AZ Microsoft Excel Programming 1 24th Oct 2010 06:14 PM
form refresh? repaint? doevents? aaron.kempf@gmail.com Microsoft VB .NET 2 11th Apr 2006 08:01 PM
Application.DoEvents after closing a form Steven Nagy Microsoft Dot NET Compact Framework 2 12th Mar 2006 10:37 PM
DoEvents for a single form? =?Utf-8?B?QmVhbkRvZw==?= Microsoft Dot NET Framework Forms 1 23rd Oct 2005 07:54 AM
DoEvents causes form to hang kahwon t via DotNetMonster.com Microsoft Dot NET Framework Forms 3 21st Jun 2005 10:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:28 PM.