[Mono-bugs] [Bug 410302] New: Misleading exception message when trying to restart a thread

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Jul 18 07:10:52 EDT 2008


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


           Summary: Misleading exception message when trying to restart a
                    thread
           Product: Mono: Class Libraries
           Version: 1.9.0
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: Minor
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: aaragoneses at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


It seems that .NET class libraries don't allow you to restart, again, a thread
that was already started and terminated.

So given this small program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace ConsoleApplication1
{
    public class MovingThread
    {
        public MovingThread()
        {
            gThread = new Thread(new ThreadStart(Run));
        }

        private void Run()
        {
            if (deleg != null)
                deleg.Invoke();
        }
        private ThreadStart deleg;
        private Thread gThread;

        public ThreadStart Deleg
        {
            set { deleg = value; }
        }

        public Thread GThread
        {
            get { return gThread; }
        }
    }

    public class Program
    {
        static void Run()
        {
            Console.WriteLine("method run!");
        }

        static void Main(string[] args)
        {
            MovingThread guiThread = new MovingThread();
            guiThread.Deleg = Run;
            guiThread.GThread.Start();
            guiThread.GThread.Join();
            guiThread.GThread.Start();
        }

    }
}

If you run it, MS.NET throws this exception:

Unhandled Exception: System.Threading.ThreadStateException: Thread is running
or
 terminated; it cannot restart.
   at System.Threading.Thread.StartupSetApartmentStateInternal()
   at System.Threading.Thread.Start()

However, Mono gives a different message, which could lead to a confusion to the
developer, making him to think that the problem is about the state of the
thread:

Unhandled Exception: System.Threading.ThreadStateException: Thread has already
been started.
  at (wrapper managed-to-native) System.Threading.Thread:Thread_internal
(System.MulticastDelegate)
  at System.Threading.Thread.Start () [0x00034] in
/home/knocte/Documents/iDocs/Proyectos/a11ymono/mcs/class/corlib/System.Threading/Thread.cs:759


-- 
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