当前位置: 首页>>代码示例>>C#>>正文


C# ThreadPriority类代码示例

本文整理汇总了C#中ThreadPriority的典型用法代码示例。如果您正苦于以下问题:C# ThreadPriority类的具体用法?C# ThreadPriority怎么用?C# ThreadPriority使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ThreadPriority类属于命名空间,在下文中一共展示了ThreadPriority类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ThreadPool

        public ThreadPool(int initialThreadCount, int maxThreadCount, string poolName,
                           int newThreadTrigger, int dynamicThreadDecayTime,
                           ThreadPriority threadPriority, int requestQueueLimit)
        {
            SafeWaitHandle = _stopCompleteEvent.SafeWaitHandle;

            if (maxThreadCount < initialThreadCount)
            {
                throw new ArgumentException("Maximum thread count must be >= initial thread count.", "maxThreadCount");
            }
            if (dynamicThreadDecayTime <= 0)
            {
                throw new ArgumentException("Dynamic thread decay time cannot be <= 0.", "dynamicThreadDecayTime");
            }
            if (newThreadTrigger <= 0)
            {
                throw new ArgumentException("New thread trigger time cannot be <= 0.", "newThreadTrigger");
            }
            ExceptionHelper.ThrowIfArgumentNullOrEmptyString(poolName, "poolName");

            _initialThreadCount = initialThreadCount;
            _maxThreadCount = maxThreadCount;
            _requestQueueLimit = (requestQueueLimit < 0 ? DEFAULT_REQUEST_QUEUE_LIMIT : requestQueueLimit);
            _decayTime = dynamicThreadDecayTime;
            _newThreadTrigger = new TimeSpan(TimeSpan.TicksPerMillisecond * newThreadTrigger);
            _threadPriority = threadPriority;
            _requestQueue = new Queue<WorkRequest>();

            _threadPoolName = poolName;
        }
开发者ID:footprint4me,项目名称:objectpool,代码行数:30,代码来源:ThreadPool.cs

示例2: PipeServiceClientChannel

		internal PipeServiceClientChannel(PipeServiceClient client, ThreadPriority listenThreadPriority, int receiveTimeout, int sendTimeout)
		{
			this.client = client;

			this.receiveTimeout = receiveTimeout;
			this.sendTimeout = sendTimeout;
		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:7,代码来源:PipeServiceClientChannel.cs

示例3: NUnitConfiguration

        /// <summary>
        /// Class constructor initializes fields from config file
        /// </summary>
        static NUnitConfiguration()
        {
            try
            {
                NameValueCollection settings = GetConfigSection("NUnit/TestCaseBuilder");
                if (settings != null)
                {
                    string oldStyle = settings["OldStyleTestCases"];
                    if (oldStyle != null)
                            allowOldStyleTests = Boolean.Parse(oldStyle);
                }

                settings = GetConfigSection("NUnit/TestRunner");
                if (settings != null)
                {
                    string apartment = settings["ApartmentState"];
                    if (apartment != null)
                        apartmentState = (ApartmentState)
                            System.Enum.Parse(typeof(ApartmentState), apartment, true);

                    string priority = settings["ThreadPriority"];
                    if (priority != null)
                        threadPriority = (ThreadPriority)
                            System.Enum.Parse(typeof(ThreadPriority), priority, true);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("Invalid configuration setting in {0}",
                    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                throw new ApplicationException(msg, ex);
            }
        }
开发者ID:scottwis,项目名称:eddie,代码行数:36,代码来源:NUnitConfiguration.cs

示例4: BenchmarkWithThreads

        /// <summary>
        /// Замеряет и выводит на экран время потраченное на решение уравнений с использованием потоков
        /// </summary>
        /// <param name="totalEquationCount">Общее количество уравнений которые необходимо решить. Делится между потоками</param>
        /// <param name="threadCount">Кол-во потоков которые следует использовать для параллельного решения уравнений</param>
        /// <param name="priority">Приоритет потока</param>
        private static void BenchmarkWithThreads(int totalEquationCount, int threadCount, ThreadPriority priority = ThreadPriority.Normal)
        {
            if (totalEquationCount % threadCount != 0) throw new Exception();

            Console.Write("Время на решение  с потоками: ");
            int itemsPerThread = totalEquationCount / threadCount; // Кол-во уравнений для каждого потока

            Stopwatch watch = Stopwatch.StartNew();
            Thread[] solveThreads = new Thread[threadCount];
            for (int i = 0, offset = 0; i < solveThreads.Length; i++, offset += itemsPerThread)
            {
                solveThreads[i] = new Thread(SolveThread)
                {
                    Name = String.Format("Решатель уравнений #{0}", i + 1),
                    Priority = priority
                };
                solveThreads[i].Start(itemsPerThread);
            }
            foreach (Thread solveThread in solveThreads)
            {
                solveThread.Join();
            }
            watch.Stop();
            Console.WriteLine("{0:F4} сек. Кол-во потоков: {1}. Приоритет: {2}", watch.Elapsed.TotalSeconds, threadCount, PriorityToString(priority));
        }
开发者ID:bazile,项目名称:Training,代码行数:31,代码来源:Program.cs

示例5: ChangeThreadPriority

 public void ChangeThreadPriority(ThreadPriority priority)
 {
     if (_thread != null)
     {
         _thread.Priority = priority;
     }
 }
开发者ID:Nandaka,项目名称:Archive-Comparer-2,代码行数:7,代码来源:ArchiveDuplicateDetector.cs

示例6: Repeat

        public void Repeat(string name, Action action, Action<Exception> onException, int interval = 100, ThreadPriority priority = ThreadPriority.Normal, CancellationToken? cancellationToken = null)
        {
            var thread = new Thread(
                () =>
                {
                    try
                    {
                        while (true)
                        {
                            if (cancellationToken.HasValue && cancellationToken.Value.IsCancellationRequested)
                                break;

                            Sleep(interval);
                            action();
                        }
                    }
                    catch (Exception e)
                    {
                        onException(e);
                    }
                }
            );
            thread.Run(priority);
            Register(thread, cancellationToken, name);
        }
开发者ID:ReactiveServices,项目名称:ReactiveServices.MessageBus,代码行数:25,代码来源:ThreadExecutor.cs

示例7: TaskSchedulerWithCustomPriority

		public TaskSchedulerWithCustomPriority(int maxThreads, ThreadPriority threadPriority)
		{
			if (maxThreads < 1) throw new ArgumentOutOfRangeException("maxThreads");

			this.maxThreads = maxThreads;
			_threadPriority = threadPriority;
		}
开发者ID:jaircazarin,项目名称:ravendb,代码行数:7,代码来源:TaskSchedulerWithCustomPriority.cs

示例8: SingleThreadTaskScheduler

		public SingleThreadTaskScheduler(string name = null, ThreadPriority priority = ThreadPriority.Normal, ApartmentState apartmentState = ApartmentState.STA)
		{
#if DEBUG
			_allocStackTrace = new StackTrace();
#endif

			_thread = new Thread(
				() =>
				{
					try
					{
						foreach (var task in _queue.GetConsumingEnumerable())
							TryExecuteTask(task);
					}
					finally
					{
						_queue.Dispose();
					}
				});

			_thread.IsBackground = true;
			_thread.Name = name;
			_thread.Priority = priority;
			_thread.SetApartmentState(apartmentState);

			_thread.Start();
		}
开发者ID:slorion,项目名称:nlight,代码行数:27,代码来源:SingleThreadTaskScheduler.cs

示例9: Thread

 internal Thread(ThreadStart threadStart, ThreadPriority priority, SIP sip, TaskHandle task)
 {
     Task = task;
     _threadStart = threadStart;
     _priority = priority;
     _sip = sip;
 }
开发者ID:sidecut,项目名称:xaeios,代码行数:7,代码来源:Thread.cs

示例10: SetThreadPriority

 public static void SetThreadPriority(ThreadPriority priority)
 {
     if (Thread.CurrentThread.Priority != priority)
     {
         Thread.CurrentThread.Priority = priority;
     }
 }
开发者ID:lamp525,项目名称:DotNet,代码行数:7,代码来源:ThreadHelper.cs

示例11: EvoThreads

        public EvoThreads(int threads, ThreadPriority priority)
        {
            // If the thread count is less than one or greater than the number of processors, throw an argument out of range exception
            if (threads < 1 || threads > Environment.ProcessorCount)
                throw new ArgumentOutOfRangeException("threads");

            // Initialize the threads array
            this._threads = new Thread[threads];

            // Initialize the event arrays
            this._resume = new AutoResetEvent[threads];
            this._waiting = new ManualResetEvent[threads];

            for (int i = 0; i < threads; i++)
            {
                // Create each thread in the threads array
                this._threads[i] = new Thread(new ParameterizedThreadStart(this.ThreadStart));

                //Set Priority
                this._threads[i].Priority = priority;

                // Set the properties for each thread in the threads array
                this._threads[i].IsBackground = true;

                // Create each element in the event arrays
                this._resume[i]  = new AutoResetEvent(false);
                this._waiting[i] = new ManualResetEvent(true);

                // Start each thread in the threads array
                this._threads[i].Start(i);
            }
        }
开发者ID:reuxertz,项目名称:information-approach,代码行数:32,代码来源:EvoThreads.cs

示例12: Work

 public Work()
 {
   _state = WorkState.INIT;
   _description = string.Empty;
   _priority = ThreadPriority.Normal;
   _eventArgs = new WorkEventArgs(this);
 }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:7,代码来源:Work.cs

示例13: BackgroundTaskQueueProvider

        public BackgroundTaskQueueProvider(ThreadPriority priority)
        {
            // set up the task queue
            _queue = new List<string>();

            // spin up the threads - two per logical CPU
            _maximumThreads = Environment.ProcessorCount * 2;
            #if DEBUG
            // if we're debugging, multithreading is a pain in the ass
            _maximumThreads = 1;
            #endif

            for (int i = 0; i < _maximumThreads; i++)
            {
                _threadStates.Add(i.ToString(), false);
            }

            for (int i = 0; i < _maximumThreads; i++)
            {
                Thread thread = new Thread(Processor)
                                     {
                                         Priority = priority,
                                         IsBackground = false,
                                         Name = i.ToString(CultureInfo.InvariantCulture)
                                     };
                thread.Start();
                _threadPool.Add(i.ToString(), thread);
            }
        }
开发者ID:rev2004,项目名称:certitude,代码行数:29,代码来源:BackgroundTaskQueueProvider.cs

示例14: SingleThreadExecutor

        /// <summary>
        /// Creates a new <c>SingleThreadExecutor</c> using a custom thread priority.
        /// </summary>
        /// <param name="priority">
        /// The priority to assign the thread.
        /// </param>
        public SingleThreadExecutor(ThreadPriority priority) {
            _actions = new BlockingQueue<Action>();
            _running = new AtomicBoolean(false);
            _shuttingDown = new AtomicBoolean(false);

            _priority = priority;
        }
开发者ID:mbolt35,项目名称:CSharp.Atomic,代码行数:13,代码来源:SingleThreadExecutor.cs

示例15: ThreadBackground

        public ThreadBackground(ThreadBackgroundFlags flags)
        {
            this.flags = flags;
            this.currentThread = Thread.CurrentThread;
            this.oldThreadPriority = this.currentThread.Priority;

            if ((flags & ThreadBackgroundFlags.Cpu) == ThreadBackgroundFlags.Cpu &&
                (activeFlags & ThreadBackgroundFlags.Cpu) != ThreadBackgroundFlags.Cpu)
            {
                this.currentThread.Priority = ThreadPriority.BelowNormal;
                activeFlags |= ThreadBackgroundFlags.Cpu;
            }

            if (Environment.OSVersion.Version >= OS.WindowsVista &&
                (flags & ThreadBackgroundFlags.IO) == ThreadBackgroundFlags.IO &&
                (activeFlags & ThreadBackgroundFlags.IO) != ThreadBackgroundFlags.IO)
            {
                IntPtr hThread = SafeNativeMethods.GetCurrentThread();
                bool bResult = SafeNativeMethods.SetThreadPriority(hThread, NativeConstants.THREAD_MODE_BACKGROUND_BEGIN);

                if (!bResult)
                {
                    NativeMethods.ThrowOnWin32Error("SetThreadPriority(THREAD_MODE_BACKGROUND_BEGIN) returned FALSE");
                }
            }

            activeFlags |= flags;

            ++count;
        }
开发者ID:metadeta96,项目名称:openpdn,代码行数:30,代码来源:ThreadBackground.cs


注:本文中的ThreadPriority类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。