Slow Performance of Linq Where statement #4713
Unanswered
MohanramAnbukkarasu
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You're executing your operations on the UI thread, thus blocking it from processing it other important messages such as repaint. This essentially makes your app look unresponsive. Long running and/or CPU heavy work should be performed on a background thread, and marshaled back to the UI thread when necessary, e.g. to update the UI with the progress. You may find these resources useful: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have an ObservableCollection with 4 lakhs unique items. On a button click event, I execute a Linq Where query to set value for a bool value in the items of the collection.
`
List DistinctCollection = new List();
List filteredCollection = new List();
for(int i=1;i<=400000; i++)
{
DistinctCollection.Add(new DataClass() { Content = i.ToString() });
}
filteredCollection = DistinctCollection.Where(x => x.Content.Contains("2")).ToList();
private void button1_Click(object sender, EventArgs e)
{
// The problem occurs here.
DistinctCollection.Where(x => filteredCollection.Contains(x)).Select(x => x.IsSelected = true).ToList();
DistinctCollection.Where(x => !filteredCollection.Contains(x)).Select(x => x.IsSelected = false).ToList();
}
`
Please use below given sample application to reproduce the problem.
The query works properly when the number of items in the collection is less. But the UI freeze when executing the query if the collection contains 4 lakhs and above items. Is there any possible way to improve the performance of this query?
Thanks in advance.
Linq.Where_Demo.zip
Beta Was this translation helpful? Give feedback.
All reactions