Click to See Complete Forum and Search --> : Prob w/event handler inside a window opened with Show()


purpleflash
February 19th, 2009, 05:32 AM
Here's the situation: my application opens one or more child windows with Show() which allow the users to perform several functions, while also being able to click back to the main application.

In each of these child windows I create an event handler, which fires when a new email is received.

This work fine (the event handler is called) however as soon as the code in the event handler begins to execute it just stops. That is, using the debugger I can tell that the event handler has been fired, but when the first line in the handler's code (and this can be something as simple as 'string s = ""'; ) is executed execution of the handler stops.

Is this a threading issue, and is there something I can do to work around it?

Using .Net 3.5SP1

dannystommen
February 19th, 2009, 06:36 AM
Can you provice the code where this is happening?

purpleflash
February 19th, 2009, 11:17 AM
objOutlook.NewMail += new ApplicationEvents_NewMailEventHandler(objOutlook_NewMail);


sets up the event handler... and


void objOutlook_NewMail()
{
textBlock2.Text = "Mail Received";
Message ms = new Message("Notice","New mail received");
ms.ShowDialog();

}


is the handler. When the 'textBlock2.Text = "Mail Received"' statement executes, execution stops, the textBlock2.Text property doesn't get updated, nada... execution of the event code just ceases. This is always on the first statement of the event handler, no matter what it is.

dannystommen
February 19th, 2009, 12:28 PM
What happens when you put it in a try/catch


void objOutlook_NewMail()
{
try
{
textBlock2.Text = "Mail Received";
Message ms = new Message("Notice","New mail received");
ms.ShowDialog();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}


I have had similar problem, crashing on a line without throwing an exception. But when I inserted the try/catch, there was an exception caught

cjard
February 19th, 2009, 07:00 PM
How can you tell it has fired but then stops?