Solved

Reentrancy Problem

Posted on 2001-06-05
10
209 Views
Last Modified: 2010-05-02
A activex control is refered in my VB project,I get a message when the control fire an event.but I find that
when I processes a message with this event,this event is triggered again before the processing for the original message is finished.
uses a global BOOL variable to detect reentrancy maybe helpful,but some messages will be lost in this way.
any help on this subject would be very appreciated.
0
Comment
Question by:fenghood
  • 5
  • 3
  • 2
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6158457
We need to know how this event is triggered.
0
 

Author Comment

by:fenghood
ID: 6158641
Richie simonetti:
  I fire this event using COleControl::FireEvent function
in VC++,when I get some messages,this event is fired at the
end of each message handler.
  need your help,thanks.
0
 

Author Comment

by:fenghood
ID: 6158723
Richie simonetti:
  I fire this event using COleControl::FireEvent function
in VC++,when I get some messages,this event is fired at the
end of each message handler.
  need your help,thanks.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 2

Expert Comment

by:WalterM
ID: 6159237
It may be the case that one of the statements in your VB event handler implementation retriggers the event, e.g. if you manipulate the ActiveX control from within the event handler by calling one or more member functions.

If it is desirable behaviour that touching these control members raises an event, simply protect the VB event handlers from reentry by using a local static Boolean flag, i.e.

Private Sub YourEventHandler()
    Static ReEntry As Boolean
   
    If ReEntry Then Exit Sub
    ReEntry = True
   
    '... implementation code ...
   
    ReEntry = False
End Sub

Note that VB itself also shows this behaviour sometimes, e.g. if you change a form's size form within the Resize event, reentry will occur and you need to protect the Form_Resize event handler in the same way.

Michel
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6160690
fenghood, Michel post would help you.
0
 

Author Comment

by:fenghood
ID: 6166525
WalterM :
  any more,if I create a thread in Activex control with
CreateThread() function,how does VB deal with this?
  As we know,VB don't support mutil-threaded,VB application' thread pool is set to 1 thread by default and can't be changed.My Activex control is apartment thread model,apartment should reside in the thread that create
object of control.
  I can't understand this very clearly,would u help me?
0
 
LVL 2

Accepted Solution

by:
WalterM earned 100 total points
ID: 6167325
Sorry fenghood, but my experience in VB multithreading is limited to some samples I've studied now and then.

VB does support it to a certain degree, i.e. apartment-model threading, but no free-threading.

You might be able to obtain some useful information concerning multithreading and firing events by following these MSDN links:

"Events: From an ATL Server to a Visual Basic Sink"
http://msdn.microsoft.com/library/techart/msdn_atlevnts.htm

"PRB: Firing Event in Second Thread Causes IPF or GPF"
http://support.microsoft.com/support/kb/articles/Q196/0/26.ASP

"SAMPLE: ATLCPImplMT Encapsulates ATL Event Firing Across COM Apartments"
http://support.microsoft.com/support/kb/articles/Q280/5/12.ASP

"Fireev.exe Fires Events from a Second Thread"
http://support.microsoft.com/support/kb/articles/q157/4/37.asp

Michel
0
 

Author Comment

by:fenghood
ID: 6170374
thanks a lot
0
 
LVL 2

Expert Comment

by:WalterM
ID: 6177223
Thanx for the points, fenghood, hope the articles help.

Michel
0
 

Author Comment

by:fenghood
ID: 6179655
they are very helpful :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 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