Ejemplo n.º 1
0
 /// <summary>
 /// Causes the operating system to change the state of the current SThread instance to ThreadState.Running
 /// </summary>
 public virtual void Start()
 {
     StartStack = SafeThreadPool.StackTraceString();
     if (this.IsPoolThread)
     {
         ManualResetEvent mre   = null;
         bool             useRE = !IsBackground;
         if (useRE)
         {
             mre = new System.Threading.ManualResetEvent(false);
             AddOnThreadSet("Block start since this is not backgrounded ",
                            (o) =>
             {
                 try
                 {
                     mre.Set();
                 }
                 catch
                 {
                 }
             });
         }
         ThreadPool.QueueUserWorkItem(RunningFromThreadPool);
         if (useRE)
         {
             mre.WaitOne();
         }
         return;
     }
     threadField.Start();
 }
Ejemplo n.º 2
0
        private void MakeThis0(bool needMakeThread)
        {
            CreationStack = CreationStack ?? SafeThreadPool.StackTraceString();
            bool specialSize = size != -2;

            if (needMakeThread && !specialSize && !PreventPoolThread)
            {
                if (AttemptRunNewThreadsInThreadPool)
                {
                    needMakeThread = false;
                    IsPoolThread   = true;
                    if (_nativeThread != null)
                    {
                        // reuse Warning
                        needMakeThread    = true;
                        IsPoolThread      = false;
                        PreventPoolThread = true;
                        _nativeThread     = null;
                    }
                }
            }
            if (needMakeThread)
            {
                PreventPoolThread = true;
                threadField       = specialSize ? new NativeThread(RunIt, size) : new NativeThread(RunIt);
            }
            if (threadField != null)
            {
                lock (AllThreads2Safe) AllThreads2Safe[threadField] = this;
            }
        }