I have a listbox in xaml.I have to fetch a list of string from database and then have to display them in the listbox.The count of the items can be maximum 30,000.
I am fetching the data but when I am adding it in the listbox it crashes giving "Out of Memory Exception".
My Code:-
List
Dispatcher.BeginInvoke(() =>
{
listbox.Items.Clear();
foreach (string str in lstOfVals)
{
TextPhoneControl tpc = new TextPhoneControl ();
tpc.shorthandValue.Text = str;
listbox.Items.Add(tpc);
}
});

VulpesRank #55 · 29.2K reputationPosted Mar 3, 2015, 12:48 AM EST
If you just add the strings themselves it will save a lot of memory.
Sweta Sinha53 reputationPosted Mar 3, 2015, 12:50 AM EST
VulpesRank #55 · 29.2K reputationPosted Mar 3, 2015, 1:16 AM EST
Asfend YarRank #627 · 3.8K reputationPosted Mar 2, 2016, 10:12 AM EST
Gokhul VarmanRank #1,505 · 1.1K reputationPosted Jul 28, 2017, 1:08 AM EDT
Sweta Sinha53 reputationPosted Mar 3, 2015, 1:39 AM EST