BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.SystemException System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates an error that causes a exception to be thrown.

`using System; using System.Threading; public class ThreadWork { public static void DoWork() { Console.WriteLine("Working thread..."); } } class ThreadStateTest{ public static void Main() { ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork); Thread myThread = new Thread(myThreadDelegate); myThread.Start(); Thread.Sleep(0); Console.WriteLine("In main. Attempting to restart myThread."); try { myThread.Start(); } catch (ThreadStateException e) { Console.WriteLine("Caught: {0}", e.Message); } } }`

The output is

Working thread...

In main. Attempting to restart myThread.

Caught: Thread is running or terminated. Cannot restart.

Once a thread is created, it is in at least one of the states until it terminates. ThreadStateException is thrown by methods that cannot perform the requested operation due to the current state of a thread. For example, trying to restart an aborted thread by calling on a thread that has terminated throws a .

uses the HRESULT COR_E_THREADSTATE, which has the value 0x80131520.

For a list of initial property values for an instance of , see the constructors.

The exception that is thrown when a is in an invalid for the method call.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the Message property of the new instance to a system-supplied message that describes the error, such as "The requested operation cannot be performed on the thread due to its current state." This message takes into account the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  null.

  The localized error message string.

  Initializes a new instance of the class with default properties.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the Message property of the new instance using the parameter.

  The following table shows the initial property values for an instance of .

  Property

  Value

  null.

  The error message string.

  Initializes a new instance of the class with a specified error message.

  The error message that explains the reason for the exception.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see [<topic://cpconSerialization>].

  Initializes a new instance of the class with serialized data.

  The that holds the serialized object data about the exception being thrown.
  The that contains contextual information about the source or destination.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  The error message string.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The exception that is the cause of the current exception. If the parameter is not null, the current exception is raised in a catch block that handles the inner exception.
  0
0