internal string GetHeader(LogLevel level, string ThreadName, int threadId, ThreadPriority threadPriority)
        {
            MethodBase method    = new StackTrace().GetFrame(2).GetMethod();
            string     className = method.ReflectedType.Name;

            string date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss \"GMT\"zzz");

            return(date + " [" + className + "] " + threadPriority.ToString() + " \"" + ThreadName + "\" {" + threadId.ToString() + "} " + level.ToString() + ": ");
        }
Exemplo n.º 2
0
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
                                               IMessage requestMsg,
                                               ITransportHeaders requestHeaders,
                                               Stream requestStream,
                                               out IMessage responseMsg,
                                               out ITransportHeaders responseHeaders,
                                               out Stream responseStream)
        {
            LogicalCallContext lcc =
                (LogicalCallContext)requestMsg.Properties["__CallContext"];

            // storing the current priority
            ThreadPriority oldprio = Thread.CurrentThread.Priority;

            // check if the logical call context contains "priority"
            if (lcc != null && lcc.GetData("priority") != null)
            {
                // fetch the priorty from the call context
                ThreadPriority priority =
                    (ThreadPriority)lcc.GetData("priority");

                Console.WriteLine("  -> Pre-execution priority change {0} to {1}",
                                  oldprio.ToString(), priority.ToString());

                // set the priority
                Thread.CurrentThread.Priority = priority;
            }



            // push on the stack and pass the call to the next sink
            // the old priority will be used as "state" for the response
            sinkStack.Push(this, oldprio);
            ServerProcessing spres = _next.ProcessMessage(sinkStack,
                                                          requestMsg, requestHeaders, requestStream,
                                                          out responseMsg, out responseHeaders, out responseStream);

            //restore priority if call is not asynchronous

            if (spres != ServerProcessing.Async)
            {
                if (lcc != null && lcc.GetData("priority") != null)
                {
                    Console.WriteLine("  -> Post-execution change back to {0}", oldprio);
                    Thread.CurrentThread.Priority = oldprio;
                }
            }

            return(spres);
        }
Exemplo n.º 3
0
        public static void Main()
        {
            Console.WriteLine("按下任一按鍵,開始產生執行緒,並且執行");
            Console.ReadKey();

            // 產生一個新的 Thread,當該Thread啟動之後,會執行 [執行緒方法] 方法
            #region 執行緒優先權為 Lowest
            Thread         t2 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority2 = ThreadPriority.Lowest;
            t2.Name     = "執行緒優先權 " + fooThreadPriority2.ToString();
            t2.Priority = fooThreadPriority2;
            t2.Start("2");
            #endregion

            #region 執行緒優先權為 BelowNormal
            Thread         t3 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority3 = ThreadPriority.BelowNormal;
            t3.Name     = "執行緒優先權 " + fooThreadPriority3.ToString();
            t3.Priority = fooThreadPriority3;
            t3.Start("3");
            #endregion

            #region 執行緒優先權為 Normal
            Thread         t4 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority4 = ThreadPriority.Normal;
            t4.Name     = "執行緒優先權 " + fooThreadPriority4.ToString();
            t4.Priority = fooThreadPriority4;
            t4.Start("4");
            #endregion

            #region 執行緒優先權為 AboveNormal
            Thread         t5 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority5 = ThreadPriority.AboveNormal;
            t5.Name     = "執行緒優先權 " + fooThreadPriority5.ToString();
            t5.Priority = fooThreadPriority5;
            t5.Start("5");
            #endregion

            #region 執行緒優先權為 Highest
            Thread         t6 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority6 = ThreadPriority.Highest;
            t6.Name     = "執行緒優先權 " + fooThreadPriority6.ToString();
            t6.Priority = fooThreadPriority6;
            t6.Start("6");
            #endregion

            Console.WriteLine("按下任一按鍵,結束處理程序");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void 模擬不同執行緒的執行()
        {
            // 產生一個新的 Thread,當該Thread啟動之後,會執行 [執行緒方法2] 方法
            #region 執行緒優先權為 Lowest
            Thread         t2 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority2 = ThreadPriority.Lowest;
            t2.Name     = "執行緒優先權 " + fooThreadPriority2.ToString();
            t2.Priority = fooThreadPriority2;
            t2.Start("2");
            #endregion

            #region 執行緒優先權為 BelowNormal
            Thread         t3 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority3 = ThreadPriority.BelowNormal;
            t3.Name     = "執行緒優先權 " + fooThreadPriority3.ToString();
            t3.Priority = fooThreadPriority3;
            t3.Start("3");
            #endregion

            #region 執行緒優先權為 Normal
            Thread         t4 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority4 = ThreadPriority.Normal;
            t4.Name     = "執行緒優先權 " + fooThreadPriority4.ToString();
            t4.Priority = fooThreadPriority4;
            t4.Start("4");
            #endregion

            #region 執行緒優先權為 AboveNormal
            Thread         t5 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority5 = ThreadPriority.AboveNormal;
            t5.Name     = "執行緒優先權 " + fooThreadPriority5.ToString();
            t5.Priority = fooThreadPriority5;
            t5.Start("5");
            #endregion

            #region 執行緒優先權為 Highest
            Thread         t6 = new Thread(new ParameterizedThreadStart(執行緒方法));
            ThreadPriority fooThreadPriority6 = ThreadPriority.Highest;
            t6.Name     = "執行緒優先權 " + fooThreadPriority6.ToString();
            t6.Priority = fooThreadPriority6;
            t6.Start("6");
            #endregion
        }
Exemplo n.º 5
0
    private IEnumerator GetWWW(ThreadPriority tPri)
    {
        www = new WWW(url);
        www.threadPriority = tPri;
        int frames = 0;
        while (!www.isDone)
        {
            m_info = "Loading... " + frames;
            frames++;
            yield return new WaitForEndOfFrame();
        }

        if (string.IsNullOrEmpty(www.error))
        {
            m_info = "Done! Thread priority: " + tPri.ToString();
            aBundle = (GameObject)Instantiate(www.assetBundle.mainAsset);
        }
        else
            m_info = www.error;
    }
Exemplo n.º 6
0
        static string PriorityToString(ThreadPriority priority)
        {
            switch (priority)
            {
            case ThreadPriority.Lowest:
                return("Самый низкий");

            case ThreadPriority.BelowNormal:
                return("Ниже нормального");

            case ThreadPriority.Normal:
                return("Нормальный");

            case ThreadPriority.AboveNormal:
                return("Выше нормального");

            case ThreadPriority.Highest:
                return("Самый высокий");

            default:
                return(priority.ToString());
            }
        }
Exemplo n.º 7
0
        protected override void QueueTask(Task task)
        {
            _tasks.Add(task);

            if (_threads == null)
            {
                _threads = new Thread[_maximumConcurrencyLevel];
                for (int i = 0; i < _threads.Length; i++)
                {
                    int local = i;
                    _threads[i] = new Thread(() =>
                    {
                        foreach (Task t in _tasks.GetConsumingEnumerable())
                        {
                            base.TryExecuteTask(t);
                        }
                    });
                    _threads[i].Name         = _threads[i].ManagedThreadId + " " + _priority.ToString();
                    _threads[i].Priority     = _priority;
                    _threads[i].IsBackground = true;
                    _threads[i].Start();
                }
            }
        }
Exemplo n.º 8
0
 static string PriorityToString(ThreadPriority priority)
 {
     switch (priority)
     {
         case ThreadPriority.Lowest:
             return "Самый низкий";
         case ThreadPriority.BelowNormal:
             return "Ниже нормального";
         case ThreadPriority.Normal:
             return "Нормальный";
         case ThreadPriority.AboveNormal:
             return "Выше нормального";
         case ThreadPriority.Highest:
             return "Самый высокий";
         default:
             return priority.ToString();
     }
 }