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;
            }
        }
Ejemplo n.º 3
0
 protected void RunIt()
 {
     This     = this;
     willBeBg = NativeThread.CurrentThread.IsBackground;
     try
     {
         RegisterThread(threadField);
         SafeThreadPool.SafelyAct(CreationStack, Run);
     }
     finally
     {
         DeregisterThread(NativeThread.CurrentThread);
     }
 }
Ejemplo n.º 4
0
 private void RunRunnable()
 {
     try
     {
         if (runnable1 != null)
         {
             runnable1(param);
         }
         if (runnable0 != null)
         {
             runnable0();
         }
     }
     catch (Exception e)
     {
         SafeThreadPool.Issue(threadField, e);
     }
 }
Ejemplo n.º 5
0
 public static void Notice(int level, string fmt, params object[] args)
 {
     SafeThreadPool.Notice(level, fmt, args);
 }
 public static T Safely <T>(Func <T> func)
 {
     return(SafeThreadPool.Safely(func));
 }