March 2004
Intermediate to advanced
560 pages
26h 47m
English
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);
}
}
}
}
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() ...
Read now
Unlock full access