[Mono-bugs] [Bug 417871] Thread.Abort() not working correctly.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Feb 28 13:19:38 EST 2009


https://bugzilla.novell.com/show_bug.cgi?id=417871

User fp at dti-be.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=417871#c3


Fred Peters <fp at dti-be.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fp at dti-be.com




--- Comment #3 from Fred Peters <fp at dti-be.com>  2009-02-28 11:19:36 MST ---
I got same issue with Mono 2.2 and found this bug report. So I'm adding some
more information because this is a blocking issue.
This test case works fine with Microsoft .NET

Here is a small test case to simulate the problem:

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

namespace ThreadAbort
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread thread = new Thread(Execute);
            thread.Start();
            Thread.Sleep(1000);
            thread.Abort();
            Console.WriteLine("** End **");
            Console.ReadLine();
        }

        public static void Execute()
        {
            Console.WriteLine("Thread started");
            try
            {
// This does not work (exception never thrown)
                while (true)
                    ;
// This would work
//                while (true)
//                    Thread.Sleep(1);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Thread aborted: {0}", ex.Message); 
            }
        }
    }
}

As seen in the comments above, there is a workaround using a Thread.Sleep() but
this is not acceptable because the purpose of Abort in our application is to
cancel a thread which would be blocked somewhere

Thanks

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list