/* ------------ Methods called only by FJTaskRunners ------------- */


        /// <summary> Return a task from entry queue, or null if empty.
        /// Called only by FJTaskRunner.scan().
        ///
        /// </summary>
        protected internal virtual FJTask PollEntryQueue(FJTaskRunner runner)
        {
            try
            {
                object o = entryQueue.Poll(0);
                if (o is FJTask)
                {
                    return(o as FJTask);
                }
                else if (o is InvokableCandidateFJTask)
                {
                    InvokableCandidateFJTask i = o as InvokableCandidateFJTask;
                    return(i.AsInvokableFJTask(runner));
                }
                else if (o is IRunnable)
                {
                    return(new FJTask.Wrap(o as IRunnable));
                }
                else if (o == null)
                {
                    return(null);
                }
                else
                {
                    throw new ArgumentException("unexpected object in queue", o != null ? o.GetType().Name : "null");
                }
            }
            catch (System.Threading.ThreadInterruptedException)
            {
                // ignore interrupts
                ThreadClass.Current.Interrupt();
                return(null);
            }
        }
        /// <summary> Start a task and wait it out. Returns when the task completes.</summary>
        /// <exception cref="ThreadInterruptedException">  if current Thread is
        /// interrupted before completion of the task.
        /// </exception>
        public virtual void  Invoke(IRunnable r)
        {
            InvokableCandidateFJTask w = new InvokableCandidateFJTask(r, this);

            entryQueue.Put(w);
            SignalNewTask();
            w.AwaitTermination();
        }
 /// <summary> Start a task and wait it out. Returns when the task completes.</summary>
 /// <exception cref="ThreadInterruptedException">  if current Thread is
 /// interrupted before completion of the task.
 /// </exception>		
 public virtual void Invoke(IRunnable r)
 {
     InvokableCandidateFJTask w = new InvokableCandidateFJTask(r, this);
     entryQueue.Put(w);
     SignalNewTask();
     w.AwaitTermination();
 }