开发者

Most suitable collection for multithreading requests?

I have ~10,000 records would like to keep in a collection in memory and execute LINQ queries against it. This collection should be available for all the users in the application domain and can access concurrently. I’m looking for a .NET collection that supports multithreading can query asynchronously and efficiently without any threading issues. An开发者_如何学Cy suggestions on deciding a collection for this?

Sorry - It is only to read, no updates. And it should NOT be in .NET 4.0


Do you need to update it? If not, any of the usual suspects (e.g. List<T> or an array) should be fine. If there's a natural key you want to look things up by, you may want to use a dictionary instead, but if it's really "just a collection" then a list should be fine.

EDIT: It looks like the rest of this answer is irrelevant to this particular question, but I'll leave it here for others with slightly different requirements.

If you do need to update it - and if you're able to use .NET 4 - you should at least consider ConcurrentBag. Bear in mind that it's unordered, and that if you iterate over it and modify the bag concurrently you won't see the changes (it's a snapshot, according to the docs), but if that's okay, it may well be what you're after.

If that doesn't quite do what you want, have a look at the other collections in the System.Collections.Concurrent namespace - again, this is all for .NET 4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜