I have here a desktop application with ListBox
that will accept records (files inside a directory and its sub-directories) of more than 10,000. When I assign its DataSource
with that DataTable
of more than maybe 50,000 it makes the UI hang even though it is inside the DoWork
of a BackgroundWorker
, thus, hangs also my ProgressBar
that indicates the progress of the assignment of data in the ListBox
.
I have also used the method here to avoid cross threading while assigning its DisplayMember
and ValueMember
but still it gets hang.
Here's the code:
private void bgWorkerForLstBox1_DoWork(object sender, DoWorkEventArgs e)
{
string viewPath = string.Empty;
if (radFullPath.Checked)
viewPath = "fullPath";
else if (radShortPath.Checked)
viewPath = "truncatedPath";
else
viewPath = "fileName";
if (dt1 != null)
if (dt1.Rows.Count > 0)
SetListBox1Props(viewPath, "fullPath");
}
delegate void SetListBox1PropsCallback(string DisplayMember, string ValueMember);
private void SetListBox1Props(string DisplayMember, string ValueMember)
{
if (this.lstBox1.InvokeRequired)
{
SetListBox1PropsCallback d = new SetListBox1PropsCallback(SetListBox1Props);
this.Invoke(d, new object[] { DisplayMember, ValueMember });
}
else
{
this.lstBox1.DataSource = dt1;
this.lstBox1.DisplayMember = DisplayMember;
this.lstBox1.ValueMember = ValueMember;
}
}