using System.Threading;

namespace BulkPrinting
{
    public abstract class ThreadHelper
    {
        protected Thread _thread;
        protected object _lock = new object();
        protected bool _cancelled;

        public ThreadHelper()
        {
            _thread = new Thread(Run);
        }

        public void Abort()
        {
            _thread.Abort();
        }

        public void Cancel()
        {
            lock (_lock)
            {
                _cancelled = true;
                Monitor.Pulse(_lock);
            }
        }

        public void Join()
        {
            _thread.Join();
        }

        protected abstract void Run();

        public void Start()
        {
            _thread.Start();
        }
    }
}
