Solved

Reentrancy Problem

Posted on 2001-06-05
10
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

691 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