Skip to content

Slow Performance of Linq Where statement #4711

Description

@MohanramAnbukkarasu

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions