DoEvents inside COM event? 
Author Message
 DoEvents inside COM event?

I have written an out-of-process (.exe) apartment-threaded
COM object in VC++6, and I make a call to it from my VB
app that can take a minute to complete.  So, I have the
COM object call an event.  VB *does* get the event and
handles it fine.  I have it set up to send back to the COM
server whether or not to continue processing.  This also
works.

To allow the user to cancel the process, I put a Cancel
button on a progress form and wrote this in the event code:

Private Sub g_DB_OnSearchResult(..., lContinue As Long)
    If bStop Then lContinue = 0

    DoEvents
End Sub

When they hit the cancel button, it sets bStop to true.  
Now, this all works.  Sometimes.  If the process doesn't
take very long (<5 seconds) I can click the cancel button
any time and it succeeds.  

But sometimes when it takes much longer, and the
OnSearchResult is called thousands of times, the DoEvents
doesn't seem to take effect.  When I click the Cancel
button it doesn't press, I just get the standard
VB "waiting for server" message box.  Any ideas?



Sun, 29 Aug 2004 03:07:19 GMT  
 DoEvents inside COM event?
Ben,

This is because the call into the ActiveX EXE is synchronous - meaning that
your standard EXE will wait until the call is finished before it continues
on to the next line of code.  So I would have to guess that your DoEvents
might not even be getting hit.

One way around this is to do an asynchronous call.  To do this you would
make a call into a function in the COM exe.  That function would simply
start a timer in the COM exe.  The function would then exit, returning
control back to your standard exe so it could continue processing.  Shortly
after the call returns to the standard exe, the timer event will fire and
execute some code in the COM exe.  Then the COM exe could raise an event
back to the standard exe to indicate that it is finished.  Your standard
exe could just sit in a DoEvents loop checking the boolean flag while it
waits for that event.

Kevin Williamson - Microsoft Visual Basic Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

--------------------
| Content-Class: urn:content-classes:message


| Subject: DoEvents inside COM event?
| Date: Tue, 12 Mar 2002 11:07:19 -0800
| Lines: 28

| MIME-Version: 1.0
| Content-Type: text/plain;
|       charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
| Thread-Index: AcHJ+SG/AHdX/MwAReC7CJqJUDc0Sw==
| Newsgroups: microsoft.public.vb.com
| NNTP-Posting-Host: TKMSFTNGXA11 10.201.226.39
| Path: cpmsftngxa07!cpmsftngxa06!cpmsftngxa08
| Xref: cpmsftngxa07 microsoft.public.vb.com:26007
| X-Tomcat-NG: microsoft.public.vb.com
|
| I have written an out-of-process (.exe) apartment-threaded
| COM object in VC++6, and I make a call to it from my VB
| app that can take a minute to complete.  So, I have the
| COM object call an event.  VB *does* get the event and
| handles it fine.  I have it set up to send back to the COM
| server whether or not to continue processing.  This also
| works.
|
| To allow the user to cancel the process, I put a Cancel
| button on a progress form and wrote this in the event code:
|
| Private Sub g_DB_OnSearchResult(..., lContinue As Long)
|     If bStop Then lContinue = 0
|
|     DoEvents
| End Sub
|
| When they hit the cancel button, it sets bStop to true.  
| Now, this all works.  Sometimes.  If the process doesn't
| take very long (<5 seconds) I can click the cancel button
| any time and it succeeds.  
|
| But sometimes when it takes much longer, and the
| OnSearchResult is called thousands of times, the DoEvents
| doesn't seem to take effect.  When I click the Cancel
| button it doesn't press, I just get the standard
| VB "waiting for server" message box.  Any ideas?
|
|



Tue, 31 Aug 2004 00:04:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DoEvents inside TrueDBGrid RowColChange Event

2. Handle a vbscript event inside a COM object

3. Firing events from a form inside a class inside a test app

4. Call to Java COM inside VB COM

5. DoEvents() inside a class?

6. 'DoEvents' inside ActiveX DLL

7. Calling COM = DoEvents??

8. DoEvents and Form_Timer event

9. DoEvents not doing any events

10. Multiple Timers, Events Queue, DoEvents Don't Work

11. Timer events have their own DoEvents?

12. Doevents doesnt do events !

 

 
Powered by phpBB® Forum Software