C# GUIDsometime just went bust.

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

    C# GUIDsometime just went bust.

    Hello,

    I'm working on a GUI C# projects with a lot of threads doing many thing.
    Basically the GUI is just a monitor of all the threads.

    Often my application suddenly shut down without any warning. Noramlly if you
    run from VS you get the Unhandled Exception dialog box, which does happen,
    but occasionally it just stopped and seems like a normal termination (not).

    Anyone has any suggestion about this issue?

    thanks,

    /m


  • Chris R

    #2
    Re: C# GUIDsometime just went bust.

    Are you using Control.Invoke for thread to GUI communication?

    When I'm building a class and I don't know if it'll be on the same thread or
    not, I use

    public void CallingMethod()
    {
    if( control1.Invoke Required )
    {
    control1.Invoke ( MyMethodHandler ,...)
    }
    else
    {
    control1.MyMeth od();
    }
    }

    where MyMethodHandler is a delegate that holds MyMethod();
    if this class is on a different thread than the GUI, it'll call the Invoke,
    if it's place on the GUI thread, it'll just call MyMethod directly.


    "Muscha" <muscha@no.spam .net> wrote in message
    news:OBiGUOaoDH A.3024@tk2msftn gp13.phx.gbl...[color=blue]
    > Hello,
    >
    > I'm working on a GUI C# projects with a lot of threads doing many thing.
    > Basically the GUI is just a monitor of all the threads.
    >
    > Often my application suddenly shut down without any warning. Noramlly if[/color]
    you[color=blue]
    > run from VS you get the Unhandled Exception dialog box, which does happen,
    > but occasionally it just stopped and seems like a normal termination[/color]
    (not).[color=blue]
    >
    > Anyone has any suggestion about this issue?
    >
    > thanks,
    >
    > /m
    >
    >[/color]


    Comment

    • Aravind C

      #3
      Re: C# GUIDsometime just went bust.

      Hi Muscha,

      As Chris suggested, if you are updating your controls from
      other threads (other than the GUI thread that created your control),
      you will need to need to use Control.Invoke( ) to marshal the call
      correctly to the GUI thread.

      One other thing you must probably try to do is handle
      exceptions in the code that raises events.

      foreach(YourDel egate del in YourEvent.GetIn vocationList())
      {
      try
      {
      del(some params);
      }
      catch(Exception ex)
      {
      // Maybe the event handler threw an exception.
      }
      }

      That way, you can trap exceptions even if your event handlers such as your
      GUI app
      terminates unexpectedly.

      Regards,
      Aravind C


      "Muscha" <muscha@no.spam .net> wrote in message
      news:OBiGUOaoDH A.3024@tk2msftn gp13.phx.gbl...[color=blue]
      > Hello,
      >
      > I'm working on a GUI C# projects with a lot of threads doing many thing.
      > Basically the GUI is just a monitor of all the threads.
      >
      > Often my application suddenly shut down without any warning. Noramlly if[/color]
      you[color=blue]
      > run from VS you get the Unhandled Exception dialog box, which does happen,
      > but occasionally it just stopped and seems like a normal termination[/color]
      (not).[color=blue]
      >
      > Anyone has any suggestion about this issue?
      >
      > thanks,
      >
      > /m
      >
      >[/color]


      Comment

      Working...