/// <summary>
 /// Creates an event thread.
 /// </summary>
 /// <param name="name">The name of the thread.</param>
 /// <param name="priority">The priority of the thread.</param>
 protected NSFThread(NSFString name, int priority)
     : base(name)
 {
     TerminationStatus = NSFThreadTerminationStatus.ThreadReady;
     OSThread          = NSFOSThread.create(Name, new NSFVoidAction <NSFContext>(threadEntry), priority);
     NSFEnvironment.addThread(this);
 }
        /// <summary>
        /// Implements the entry point for the thread.
        /// </summary>
        /// <param name="context">Additional contextual information.</param>
        private void threadEntry(NSFContext context)
        {
            try
            {
                threadLoop();
            }
            catch (Exception exception)
            {
                handleException(new Exception(Name + " thread loop exception", exception));
            }

            lock (threadMutex)
            {
                TerminationStatus = NSFThreadTerminationStatus.ThreadTerminated;
                NSFEnvironment.removeThread(this);
            }
        }