CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2006
    Posts
    199

    Prob w/event handler inside a window opened with Show()

    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

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Prob w/event handler inside a window opened with Show()

    Can you provice the code where this is happening?

  3. #3
    Join Date
    Sep 2006
    Posts
    199

    Re: Prob w/event handler inside a window opened with Show()

    Code:
                    objOutlook.NewMail += new ApplicationEvents_NewMailEventHandler(objOutlook_NewMail);
    sets up the event handler... and

    Code:
            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.

  4. #4
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Prob w/event handler inside a window opened with Show()

    What happens when you put it in a try/catch

    Code:
            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

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Prob w/event handler inside a window opened with Show()

    How can you tell it has fired but then stops?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured