是线程池适合于这个线程情况? [英] Is ThreadPool appropriate for this threading scenario?

查看:149
本文介绍了是线程池适合于这个线程情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图获取预结果的一些子元素之前,它们是由用户如果可能实际需要变成一个更加敏感的UI的场景。我对如何最好地接近螺纹不清楚,所以我希望有人能提供一些建议。



场景



有是搜索表单(.NET富客户端),使用户能够选择一个帐户对于一个给定的客户。给定文本的用户搜索,寻找客户然后将其在结果网格中显示的集合。然后,当用户选择一个客户,占该客户的列表中搜索和为了弥补最终上下文(即一个帐户)打开显示在用户选择第二栅极



现有系统



我这一切的请求/响应方式使用常规的背景线程,以解决客户的运行,分别占客户到的用户选择直接响应。用户界面被锁定/禁用(但响应),直到帐户中找到。



目标



我要什么实现是开始用户选择他们之前...其中N是被显示在网格中的项目数决算的前N客户提取



当用户滚动发车,新显示的项目将被添加到排队来获取。



问题




  1. 是线程池管理线程的适当机制?如果是这样,你可以强制只是一个单一的排队工作项目优先跳起来? - 例如如果用户选择客户,他们已经开始之前/成品取出。

  2. 如果不是,否则我应该怎么做?

  3. 无论哪种方式,都你知道任何好的博客文章和/或开源项目表现出这种功能?


解决方案

是的,线程池是一个不错的选择,也许后面的BackgroundWorker或.NET4的TaskParallel库。



但你不能(也不应该)凹凸一个线程池线程,但我不认为这将是有用的反正。



什么你应该做的是使用一个线程安全的队列(前N项),并使用2+线程来处理队列。当选择一个项目,还没有被处理,你将其向上或立即启动一个单独的线程。


I have a scenario that I'm trying to turn into a more responsive UI by pre-fetching some sub-elements of the results before they're actually required by the user if possible. I'm unclear on how best to approach the threading, so I'm hoping someone can provide some advice.

Scenario

There is search form (.NET rich client) that enable the user to select an account for a given customer. The user searches for given text to find a collection of customers which are then displayed in a result grid. Then when the user selects a customer, the list of accounts for that customer are searched for and displayed in a second grid for user selection in order to make up the final context (that is an account) to open.

Existing System

I have this all running in a request/response manner using regular background threading to resolve customers and accounts for a customer respectively in direct response to the user selections. The UI is locked/disabled (but responsive) until the accounts are found.

Goal

What I want to achieve is to commence fetching of the accounts for the top N customers before the user has selected them... Where N is the number of items being displayed in the grid.

As the user scrolls the grid, the newly displayed items will be added to the "queue" to be fetched.

Questions

  1. Is the thread pool an appropriate mechanism for managing the threads? If so, can you force just a single queued work item to jump up in priority? - e.g. if the user selects that customer before they have started/finished fetching.
  2. If not, what else should I be doing?
  3. Either way, are you aware of any good blog posts and/or open source projects that exhibit this functionality?

解决方案

Yes, the threadpool is a good choice, maybe behind a Backgroundworker or .NET4's TaskParallel library.

But you cannot (should not) 'bump' a ThreadPool thread but I don't think that is going to be useful anyway.

What you should probably do is to use a thread-safe queue (of the top N items) and use 2+ threads to process the Queue. When an item is selected and not yet being processed you move it up or start a separate thread immediately.

这篇关于是线程池适合于这个线程情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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