Solved

Reentrancy Problem

Posted on 2001-06-05
10
213 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 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