Solved

Reentrancy Problem

Posted on 2001-06-05
10
216 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 91
Zip Folders Using Chilkat Routines 1 75
Automatic Email Reminder 4 74
backup program with robocopy 6 74
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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

749 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