c# - How I can realize parallel search in ObservableCollection? -
i have observablecollection, item has 2 properties(for example: name , id) , collection contains of 12k elements. so, have textbox, want search elements, names contains textbox value , add together these elems in new collection.
in real-proj: silverlight, treeview(its itemsource collection) dynamically changing. , treeview changing in ui.
my problem in rendering results of search. thing if it'll parallel - saves me.
for example, code im using:
private observablecollection<icddocumentitemviewmodel> linearsearch(string searchtext) { var filteredcollection = new observablecollection<icddocumentitemviewmodel>(); if (searchtext.length > 3) { foreach (var itemviewmodel in _linearcollection) { if (!itemviewmodel.model.name.tolower().contains(searchtext.tolower())) continue; if (itemviewmodel.children.count != 0) { itemviewmodel.isexpanded = true; } filteredcollection.add(itemviewmodel); } } if(searchtext.length <= 3) { homecoming new observablecollection<icddocumentitemviewmodel>(icditemsviewmodelsmain); } homecoming filteredcollection; }
there no need have parallel processing in place normally, code should help here.
private observablecollection<icddocumentitemviewmodel> getfiltered(string filter) { observablecollection<icddocumentitemviewmodel> filteredcollection; if (filter.length > 3) { filteredcollection = new observablecollection<icddocumentitemviewmodel>(_linearcollection.where(x => x.name.tolower().contains(filter))); filteredcollection.tolist().foreach(detectchildren); } else { filteredcollection = new observablecollection<icddocumentitemviewmodel>(); } homecoming filteredcollection; } private void detectchildren(icddocumentitemviewmodel item) { item.isexpanded = item.children.any(); }
c# silverlight search parallel-processing
No comments:
Post a Comment