Click here to Skip to main content
15,905,877 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# and MySql server Pin
bdiepeveen22-Apr-08 2:49
bdiepeveen22-Apr-08 2:49 
Questionresource leak in thread termination? Pin
George_George22-Apr-08 0:01
George_George22-Apr-08 0:01 
AnswerRe: resource leak in thread termination? Pin
Reelix22-Apr-08 0:10
Reelix22-Apr-08 0:10 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 0:57
George_George22-Apr-08 0:57 
AnswerRe: resource leak in thread termination? Pin
Le centriste22-Apr-08 1:21
Le centriste22-Apr-08 1:21 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 1:29
George_George22-Apr-08 1:29 
GeneralRe: resource leak in thread termination? Pin
Le centriste22-Apr-08 1:58
Le centriste22-Apr-08 1:58 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 2:46
George_George22-Apr-08 2:46 
GeneralRe: resource leak in thread termination? Pin
Le centriste22-Apr-08 2:49
Le centriste22-Apr-08 2:49 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 3:03
George_George22-Apr-08 3:03 
GeneralRe: resource leak in thread termination? Pin
Le centriste22-Apr-08 3:07
Le centriste22-Apr-08 3:07 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 3:38
George_George22-Apr-08 3:38 
GeneralRe: resource leak in thread termination? Pin
Guffa22-Apr-08 3:30
Guffa22-Apr-08 3:30 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 3:41
George_George22-Apr-08 3:41 
GeneralRe: resource leak in thread termination? Pin
Guffa22-Apr-08 7:25
Guffa22-Apr-08 7:25 
GeneralRe: resource leak in thread termination? Pin
George_George22-Apr-08 16:54
George_George22-Apr-08 16:54 
GeneralRe: resource leak in thread termination? Pin
Guffa27-Apr-08 5:28
Guffa27-Apr-08 5:28 
GeneralRe: resource leak in thread termination? Pin
George_George27-Apr-08 17:44
George_George27-Apr-08 17:44 
GeneralRe: resource leak in thread termination? Pin
Guffa27-Apr-08 23:51
Guffa27-Apr-08 23:51 
GeneralRe: resource leak in thread termination? Pin
George_George28-Apr-08 1:27
George_George28-Apr-08 1:27 
GeneralRe: resource leak in thread termination? Pin
Guffa28-Apr-08 2:00
Guffa28-Apr-08 2:00 
GeneralRe: resource leak in thread termination? Pin
George_George28-Apr-08 2:14
George_George28-Apr-08 2:14 
Thanks Guffa,


1.

Guffa wrote:
Yes, that would be the only way of catching an exception from outside the thread. However, I don't think that a ThreadAbortException exception will cause that event to be triggered, but I can't find any documentation right now that either confirms or contradicts this.


I have verified you are correct. Here is my code. Could you review whether my code is correct please?

using System;
using System.Threading;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {

        static void ThreadProc()
        {
            Console.WriteLine("Begin sleeping ");
            Thread.Sleep(5000);
            Console.WriteLine("End sleeping ");
        }
        
        static void Foo(object sender, UnhandledExceptionEventArgs e)
        {
            Console.WriteLine("I am here ");
        }

        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Foo);

            Thread t = new Thread(Program.ThreadProc);

            t.Start();

            t.Abort();

            return;

        }
    }
}


2.

Guffa wrote:
but if a background thread is aborted because the application is ending, the exception will not be thrown.


Confused. You mean the ThreadAbortException will not be re-throw if it is caught?


regards,
George
GeneralRe: resource leak in thread termination? Pin
Guffa28-Apr-08 3:18
Guffa28-Apr-08 3:18 
GeneralRe: resource leak in thread termination? Pin
George_George28-Apr-08 3:56
George_George28-Apr-08 3:56 
GeneralRe: resource leak in thread termination? Pin
Guffa28-Apr-08 14:31
Guffa28-Apr-08 14:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.