CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    One thing I'm struggling to understand with C# threading..

    Is that a child thread throwing an exception causes the entire application to fail.. Why does it not just kill the child thread and allow the main thread to carry on living?

    Is there any way the parent thread can start the child and make itself immune to exceptions from the child?
    "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

  2. #2
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: One thing I'm struggling to understand with C# threading..

    As far I Know a child thread throws an AbortException if something going wrong and the thread is killed. So maybe it helps if your application catches the AbortException and it should be stable.

    Another possibility is to use the ThreadPool.QueueUserWorkItem() method for starting the child thread. I think there will be no return from the child thread through an exception.
    Useful or not? Rate my posting. Thanks.

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

    Re: One thing I'm struggling to understand with C# threading..

    I'lll take a look at the threadpool..

    .. for now suppose we have the code:


    Code:
    class Worker{
      public void DoWork(){
    	throw new Exception();
      }
    }
    and we start it like:

    Code:
    Thread t = new Thread(new ThreadStart(workerInstance.DoWork));
    t.Start();
    Where would you put the handling code in this?
    "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

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

    Re: One thing I'm struggling to understand with C# threading..

    Using ThreadPool, the application still exits when the child thread bombs out..
    "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

  5. #5
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: One thing I'm struggling to understand with C# threading..

    cjard,

    The following link might help you on how to handle the UnHandled exception (occurs in other part of your program including threads).

    http://msdn2.microsoft.com/en-us/lib...exception.aspx

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