调整线程和BackGroundWorker优先级 [英] Adjustment threads&BackGroundWorker priority

查看:64
本文介绍了调整线程和BackGroundWorker优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用"Thread.Priority"调整优先级线程和BackGrounWorkers?

how i can Adjustment priority threads and BackGrounWorkers with "Thread.Priority" ?

推荐答案

如果需要设置线程的优先级,则应使用Thread对象而不是BackgroundWorker.
If you need to set a thread''s priority, you should use the Thread object instead of BackgroundWorker.


通常,您不需要修改优先级.
可能没有任何危害(除非您将两个高优先级的重要线程(甚至是操作系统)设置为高优先级,但通常没有用.

我曾经做过的所有尝试都是由于误解.人们首先设计出错误的设计,然后面对问题.为了解决这些问题,他们尝试修改优先级并进行了一些改进.实际上,这些改进只是虚幻的:它们只会改变他们的比赛条件.

阅读有关种族状况的信息,可能会有所帮助: http://en.wikipedia.org/wiki/种族条件 [ ^ ].几年前,我曾经用更明确的术语来阅读同一件事:对执行顺序的不正确依赖".这个词对您有帮助吗?

—SA
Normally, you never need to modify priorities.
There may be no harm (unless you make priority two high blocking important thread, even of the OS), but usually no use.

All attempts I ever so was due to misconception. People devised wrong design first, faced with problems. To solve these problem they attempted to modify priority and got some improvements. In fact, the improvements were illusory: they only changes their race conditions.

Read on race condition, it may help a lot: http://en.wikipedia.org/wiki/Race_condition[^]. Years ago I used to read about same thing in much more definitive terminology: "Incorrect dependency on the order of execution". Does this term provide a hint for you?

—SA


在您的DoWork()中,您可以尝试
In your DoWork() you could try
Thread.CurrentThread.Priority = ThreadPriority.Lowest; // or .Highest or whatever


这篇关于调整线程和BackGroundWorker优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆