[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


           Summary: Misleading exception message when trying to restart a
           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)
        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;


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

Unhandled Exception: System.Threading.ThreadStateException: Thread is running
 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

Unhandled Exception: System.Threading.ThreadStateException: Thread has already
been started.
  at (wrapper managed-to-native) System.Threading.Thread:Thread_internal
  at System.Threading.Thread.Start () [0x00034] in

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