示例#1
0
        private static ThreadPriority MapFromOSPriority(OSThreadPriority priority)
        {
            switch (priority)
            {
            case OSThreadPriority.Idle:
            case OSThreadPriority.Lowest:
                return(ThreadPriority.Lowest);

            case OSThreadPriority.BelowNormal:
                return(ThreadPriority.BelowNormal);

            case OSThreadPriority.Normal:
                return(ThreadPriority.Normal);

            case OSThreadPriority.AboveNormal:
                return(ThreadPriority.AboveNormal);

            case OSThreadPriority.Highest:
            case OSThreadPriority.TimeCritical:
                return(ThreadPriority.Highest);

            case OSThreadPriority.ErrorReturn:
                Debug.Fail("GetThreadPriority failed");
                return(ThreadPriority.Normal);

            default:
                return(ThreadPriority.Normal);
            }
        }
示例#2
0
        private static ThreadPriority MapFromOSPriority(OSThreadPriority priority)
        {
            if (priority <= OSThreadPriority.Lowest)
            {
                // OS thread priorities in the [Idle,Lowest] range are mapped to ThreadPriority.Lowest
                return(ThreadPriority.Lowest);
            }
            switch (priority)
            {
            case OSThreadPriority.BelowNormal:
                return(ThreadPriority.BelowNormal);

            case OSThreadPriority.Normal:
                return(ThreadPriority.Normal);

            case OSThreadPriority.AboveNormal:
                return(ThreadPriority.AboveNormal);

            case OSThreadPriority.ErrorReturn:
                Debug.Fail("GetThreadPriority failed");
                return(ThreadPriority.Normal);
            }
            // Handle OSThreadPriority.ErrorReturn value before this check!
            if (priority >= OSThreadPriority.Highest)
            {
                // OS thread priorities in the [Highest,TimeCritical] range are mapped to ThreadPriority.Highest
                return(ThreadPriority.Highest);
            }
            Debug.Fail("Unreachable");
            return(ThreadPriority.Normal);
        }
示例#3
0
        private ThreadPriority GetPriority()
        {
            if (_osHandle.IsInvalid)
            {
                // The thread has not been started yet; return the value assigned to the Priority property.
                // Race condition with setting the priority or starting the thread is OK, we may return an old value.
                return(_priority);
            }

            // The priority might have been changed by external means. Obtain the actual value from the OS
            // rather than using the value saved in _priority.
            OSThreadPriority osPriority = Interop.mincore.GetThreadPriority(_osHandle);

            return(MapFromOSPriority(osPriority));
        }