473,487 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

The applicationhangs when event is being unhooked

Hi

I am developing an application using C++/CLI in Visual Studio 2005. In
my application I have following structure.

(1) Class A creates instances of Class B and Class C.
(2) Class B implements a timer function which repeatedly executes a
timer every 250 ms.
(3) Class C instance hooks for a event raised by Class B instance.
Class B always raises this event asynchronously at the end of timer
function. In the event handler class C raises another event which is
hooked by Class A.
(4) The event handler in class A eventually update the main UI control
(using control->Invoke() which executes on main thread)

Now, Class A's destructor is called from the main application thread.
In the destructor, class A first calls destructor of class B. Class
B's destructor returns after the timer is properly destroyed.
Then class A tries to unhook the class C's event. Here it hangs!!! The
unhook code is standard event unhook code using -= operator.

Can anyone guess why it hangs? In the thread window I saw that the
event handler in class A (for the event raised by class C) was waiting
on control->Invoke() method. However it does not explain to me why the
class A hangs at the point of unhooking an event raised by class C. Is
it reqd that the event handlers must be completely executed before it
can be unhooked? I dont think so. There is definitely a deadlock
situation here. But I am not able to guess it?

Anyone?

Thanks in advance
Amit Dedhia

Jun 19 '07 #1
1 1645
Amit,

Well, since it is completely a guess (you haven't shown any code which
would clarify what you are doing), I would say that you should remove the
event handler before the destructor is called. Does that fix your problem?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Amit Dedhia" <am********@yahoo.comwrote in message
news:11**********************@j4g2000prf.googlegro ups.com...
Hi

I am developing an application using C++/CLI in Visual Studio 2005. In
my application I have following structure.

(1) Class A creates instances of Class B and Class C.
(2) Class B implements a timer function which repeatedly executes a
timer every 250 ms.
(3) Class C instance hooks for a event raised by Class B instance.
Class B always raises this event asynchronously at the end of timer
function. In the event handler class C raises another event which is
hooked by Class A.
(4) The event handler in class A eventually update the main UI control
(using control->Invoke() which executes on main thread)

Now, Class A's destructor is called from the main application thread.
In the destructor, class A first calls destructor of class B. Class
B's destructor returns after the timer is properly destroyed.
Then class A tries to unhook the class C's event. Here it hangs!!! The
unhook code is standard event unhook code using -= operator.

Can anyone guess why it hangs? In the thread window I saw that the
event handler in class A (for the event raised by class C) was waiting
on control->Invoke() method. However it does not explain to me why the
class A hangs at the point of unhooking an event raised by class C. Is
it reqd that the event handlers must be completely executed before it
can be unhooked? I dont think so. There is definitely a deadlock
situation here. But I am not able to guess it?

Anyone?

Thanks in advance
Amit Dedhia

Jun 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7882
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
4003
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
4
9154
by: Vlad Hrybok | last post by:
I am using Application_End to send out a notification about application being unloaded. I found that those notifications are not being sent because the app seems to get unloaded without...
11
7708
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and...
3
2606
by: Jay-nospam | last post by:
Hi there, I am having trouble getting an ASP.NET web application to connect to another computer and passing the proper credentials and I hope someone can help me. I have a stand-alone Windows...
4
5279
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a...
11
3217
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
1
1427
by: Amit Dedhia | last post by:
Hi I am developing an application using C++/CLI in Visual Studio 2005. In my application I have following structure. (1) Class A creates instances of Class B and Class C. (2) Class B...
11
7291
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.