Invoke, threads, and exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Soulsby

    #1

    Invoke, threads, and exceptions

    If an exception is raised in a non-main thread then it is not handled.
    To get around this I created method that would use the invoke method
    on the main form to raise this exception on the main thread. For
    example:

    this.Invoke(new InvokeDelegate( this.ThreadExce ptionHandler),n ew
    object[]{o});

    However, this still does not seem to work correctly as I still get an
    unhandled exception. It does not fall back to the main() function
    where my catch all code is. Can anyone tell me whats going on?

    Thanks for any help.

    Chris
  • Jochen Kalmbach

    #2
    Re: Invoke, threads, and exceptions

    Chris Soulsby wrote:
    [color=blue]
    > If an exception is raised in a non-main thread then it is not handled.
    > To get around this I created method that would use the invoke method
    > on the main form to raise this exception on the main thread.[/color]

    Why not use:
    AppDomain.Curre ntDomain.Unhand ledException += new
    UnhandledExcept ionEventHandler (...);


    --
    Greetings
    Jochen

    Do you need a memory-leak finder ?

    Comment

    • Dan Cimpoiesu

      #3
      Re: Invoke, threads, and exceptions

      Try this:
      -Put all thread code in a big try catch
      -On the catch branch raise an user define event or invoke SendMessage API
      -After this you can handle the event in the main App (if you send an message
      override the WndProc and catch it)

      Hope this helps

      Dan Cimpoiesu


      "Chris Soulsby" <chris.soulsby@ sysinx.com> wrote in message
      news:860668f9.0 309290110.6f3d9 7eb@posting.goo gle.com...[color=blue]
      > If an exception is raised in a non-main thread then it is not handled.
      > To get around this I created method that would use the invoke method
      > on the main form to raise this exception on the main thread. For
      > example:
      >
      > this.Invoke(new InvokeDelegate( this.ThreadExce ptionHandler),n ew
      > object[]{o});
      >
      > However, this still does not seem to work correctly as I still get an
      > unhandled exception. It does not fall back to the main() function
      > where my catch all code is. Can anyone tell me whats going on?
      >
      > Thanks for any help.
      >
      > Chris[/color]


      Comment

      Working...