本文介绍了在线程池的C#低线程优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个低imprtance任务时一些cpu时间可被执行。我不希望此任务如果其他更多的导入任务运行的执行。也就是说,如果一个普通/高优先级任务来了,我想要的低重要性的任务暂停,直到重要性,任务就完成了。

I have several low-imprtance tasks to be performed when some cpu time is available. I don't want this task to perform if other more import task are running. Ie if a normal/high priority task comes I want the low-importance task to pause until the importance task is done.

有低重要性任务的一个相当大的数字要执行(50至1000)。所以我不希望创建每个任务一个线程。不过,我认为,线程池不允许某些优先权的规范,不是吗?

There is a pretty big number of low importance task to be performed (50 to 1000). So I don't want to create one thread per task. However I believe that the threadpool do not allow some priority specification, does it ?

您会怎么做解决这个问题?

How would you do solve this ?

推荐答案

当您使用线程池中的所有线程的默认优先级执行构建。如果你陷入困境与此设置会被忽略。这是你应该推出自己的线程池的情况。几年前,我扩展了来满足我的需求。这可能会满足你的为好。

When you are using the build in ThreadPool all threads execute with the default priority. If you mess with this setting it will be ignored. This is a case where you should roll your own ThreadPool. A few years ago I extended the SmartThreadPool to meet my needs. This may satisfy yours as well.

这篇关于在线程池的C#低线程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 04:59