Solved

Reentrancy Problem

Posted on 2001-06-05
10
201 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now