Example

using System;
using System.Threading;

namespace Samples
{
  public class ThreadStateExceptionSample
  {
    public static void StartHere()
    {
      Console.WriteLine("Thread: starting");
      Console.WriteLine("Thread: finishing");
    }
    public static void Main()
    {
      Thread t = new Thread(
                   new ThreadStart(StartHere));
      t.Start();
      Thread.Sleep(1000);
      Console.WriteLine("2) Thread state: {0}",
                        t.ThreadState);
      try
      {
        t.Suspend();
      }
      catch(ThreadStateException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Thread: starting Thread: finishing 2) Thread state: Stopped Exception: System.Threading.ThreadStateException: Thread is not running; it cannot be suspended. at System.Threading.Thread.SuspendInternal() at System.Threading.Thread.Suspend() at Samples.ThreadStateExceptionSample.Main() ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.