473,804 Members | 3,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The applicationhang s 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 1675
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.co m

"Amit Dedhia" <am********@yah oo.comwrote in message
news:11******** **************@ j4g2000prf.goog legroups.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
7935
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 header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
1
4028
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 same way a menu does. To do this my control needs to get notified when the user tried to click off of it. The Leave and LostFocus events of the UserControl work most of the time but not always. For example, if they click on a part of the form...
4
9225
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 Application_End ever being called. We started logging Application_Start and Application_End events and found that the number is not even: Application_Start happen more often than Application_End. My question is: What are the sutuations in which we should...
11
7765
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 the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
3
2626
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 2003 Server, ServerA, running as a Web Server that uses ASP.NET. The default.aspx file tries to access a file in a share on another computer, ServerB. ServerA and ServerB are on the same domain and are both running Windows 2003 Server.
4
5297
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 button fire even though nothing is subscribed to listen to the event. The answer is NO in a traditional Publisher/Subscriber design pattern (at least I think it is). I have stated that if nothing is subscribed, then the event never gets
11
3271
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 my object is destroyed, I want my object to un-register this event. If I don't then the object would never be destroyed until the object I passed in the constructor is destroyed. I have implemented a Dispose(), Dispose(bool), and ~Finalize...
1
1444
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 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
11
7343
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 is run again? This is causing certain error problems. 1 Why does the code run for a print preview when the report already exists? 2 What command do I use in code to find out if a report (or any other object for that matter) is already...
0
9575
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10308
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4288
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 we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.