Click here to Skip to main content
15,891,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an Asynchronous BindingList that contains objects that are manipulated on a worker thread and bound to a BindingSource on the Main UI thread with a BindingSource bound to a DataGridView.

Is there anyway possible to locate objects in my BindingList without iterating through the list?

I've looked under the hood of LINQ and it's basically a sugar coated foreach loop. Also from my understand if I implement IBindingList.Find() it's nothing more than a for-loop...

I've "tried" to synchronize/map my BindingList to a Dictionary that mirrors my BindingList and using the Dictionary to located objects and pass the results(index) to my BindingList but this is not working because there is just too much adding and removing of the objects and I can't keep things organized.

This is a high-performance app that's dealing with real-time high frequency data from the stock market. That's why I can't iterate through the BindingList, it's just too inefficient.

Can someone please give me some advice and/or solutions.

Thanks in advance,
-DA
Posted

1 solution

I think it helps

For example you have a List of Person and you have an ID and you need to locate a Person where ID = 1000


C#
var foundPeople = myList.TakeWhile(p => p != 1000);
int index = foundPeople.Count();
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 5-Mar-12 20:35pm    
Donald Allen Asked:

.

Thanks Shahin but that's actually A LOT slower than a simple for-loop. I was running that exact query and compared it to a for-loop and it under performed. I also did some research and learned that it's actually a "sugar-coated" foreach loop with some addition overhead.
Shahin Khorshidnia 5-Mar-12 20:35pm    
No, It's very very faster than for-loop. LINQ query wont initialize values when it's searching and it will initialize after using a foreach. For example:

var context = from p in Person
where p.UserName == "John"
Select p;
//Not initialized yet.

foreah(Person p in context)
{
// Now, it's initializing...
}

Therefore Linq is faster than every foreach.

And Also: Please don't write your comments like you are writing solutions. Use "Have a Question or Comment" if you have one. Thanks.
Vartan Khachatourian 5-Mar-12 20:53pm    
u could check the performance with Stopwatch!
linq's a nice performance query!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900