using System;
using System.Threading;
namespace AsterNET.Util
{
///
/// Support class used to handle threads
///
public class ThreadClass
{
/// The instance of Threading.Thread
private Thread thread;
#region ThreadClass()
///
/// Initializes a new instance of the ThreadClass class
///
public ThreadClass()
{
thread = new Thread(new ThreadStart(Run));
}
#endregion
#region ThreadClass(name)
///
/// Initializes a new instance of the Thread class.
///
/// The name of the thread
public ThreadClass(string Name)
{
thread = new Thread(new ThreadStart(Run));
this.Name = Name;
}
#endregion
#region ThreadClass(start)
///
/// Initializes a new instance of the Thread class.
///
/// A ThreadStart delegate that references the methods to be invoked when this thread begins executing
public ThreadClass(ThreadStart start)
{
thread = new Thread(start);
}
#endregion
#region ThreadClass(start, name)
///
/// Initializes a new instance of the Thread class.
///
/// A ThreadStart delegate that references the methods to be invoked when this thread begins executing
/// The name of the thread
public ThreadClass(ThreadStart start, string name)
{
thread = new Thread(start);
this.Name = name;
}
#endregion
#region Run()
///
/// This method has no functionality unless the method is overridden
///
public virtual void Run()
{
}
#endregion
#region Start()
///
/// Causes the operating system to change the state of the current thread instance to ThreadState.Running
///
public void Start()
{
thread.Start();
}
#endregion
#region Interrupt()
///
/// Interrupts a thread that is in the WaitSleepJoin thread state
///
public void Interrupt()
{
thread.Interrupt();
}
#endregion
#region Name
///
/// Gets or sets the name of the thread
///
public string Name
{
get { return thread.Name; }
set
{
if (thread.Name == null)
thread.Name = value;
}
}
#endregion
#region IsAlive
///
/// Gets a value indicating the execution status of the current thread
///
public bool IsAlive
{
get { return thread.IsAlive; }
}
#endregion
#region IsBackground
///
/// Gets or sets a value indicating whether or not a thread is a background thread.
///
public bool IsBackground
{
get { return thread.IsBackground; }
set { thread.IsBackground = value; }
}
#endregion
}
}