// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org.
// ****************************************************************
using System;
using System.Threading;
namespace NUnit.Core
{
public class ThreadUtility
{
///
/// Do our best to Kill a thread
///
/// The thread to kill
public static void Kill(Thread thread)
{
Kill(thread, null);
}
///
/// Do our best to kill a thread, passing state info
///
/// The thread to kill
/// Info for the ThreadAbortException handler
public static void Kill(Thread thread, object stateInfo)
{
try
{
if (stateInfo == null)
thread.Abort();
else
thread.Abort(stateInfo);
}
catch (ThreadStateException)
{
// This is deprecated but still needed in this case
// in order to kill the thread. The warning can't
// be disabled because the #pragma directive is not
// recognized by the .NET 1.1 compiler.
thread.Resume();
}
if ( (thread.ThreadState & ThreadState.WaitSleepJoin) != 0 )
thread.Interrupt();
}
private ThreadUtility() { }
}
}