Because there are 0.3 million rows, the MB runner data is imported and then displayed in LISTBOX ...... But the program crashes ..
I think it may be that the data volume is too large. At the same time, we need to test the performance limit of LISTBOX ...... Use the default this. listBox1.Items. Add (line );
The result is as follows:
1 million rows of data: 1 second
Row 3: 10 thousand seconds
0.1 million rows: 40 seconds
For performance, my requirement is that the LISTBOX should be loaded in 3.5 seconds ....
--------------- Main source code :-----------
Int loadRecNum = 0;
Long curtime = 0;
Private void button#click (object sender, EventArgs e)
{
OpenFileDialog openFileDlg = new OpenFileDialog ();
OpenFileDlg. Title = "Please select :";
OpenFileDlg. Filter = "*. * | *.*";
OpenFileDlg. ShowDialog ();
If (openFileDlg. CheckFileExists)
{
If (openFileDlg. FileName. Equals (""))
Return;
String pathYZM = openFileDlg. FileName;
// C452308 add txt2list
Thread t = new Thread (new ParameterizedThreadStart (
Delegate (object obj)
{
LoadRecNum = 0;
Curtime = DateTime. Now. Ticks;
// C45 big txt
// Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader (pathYZM );
// Read the first line of text
String line = sr. ReadLine ();
// Continue to read until you reach end of file
Int n = 0;
// ListBox1.Visible = false;
// ListBox1.Invoke (new EventHandler (delegate
//{
// This. listBox1.BeginUpdate ();
//}));
Form1 fm = (Form1) obj;
While (line! = Null)
{
// Thread. Sleep (5 );
// Console. WriteLine ("--" + n. ToString () + ":" + line );
N ++;
// Write the lie to console window
If (n % 1000 = 0)
{
Console. WriteLine ("--" + n. ToString () + ":" + line );
// ListBox1.Invoke (new EventHandler (delegate
//{
// ListBox1.EndUpdate ();
/// This. listBox1.BeginUpdate ();
//}));
}
Add2List (line );
Int readNum = this. settingForm. getReadNum ();
If (n> = readNum)
Break;
// Read the next line
Line = sr. ReadLine ();
// If (line = null)
// ListBox1.Invoke (new EventHandler (delegate
//{
// ListBox1.EndUpdate ();
//}));
}
// ListBox1.EndUpdate ();
// ListBox1.Visible = true;
// Close the file
Sr. Close ();
/// C45
LoadRecNum ++;
Label8.Invoke (new EventHandler (delegate
{
Label8.Text = "loaded:" + loadRecNum. ToString ();
}));
Long nowtime = DateTime. Now. Ticks;
Float span = (float) (nowtime-curtime)/(float) 10000000 ));
Int spanint = (int) span;
Label9.Invoke (new EventHandler (delegate
{
Label9.Text = "in use:" + span. ToString () + "seconds ";
}));
}
));
T. Name = "-- start txt2list thread ";
T. IsBackground = true;
T. Start (this );
// String txt = filex. read (pathYZM, "gbk ");
// String [] lines = txt. Split ("\ r \ n". ToCharArray ());
// AccFilter4ihush af = new accFilter4ihush ();
// Foreach (String line in lines)
//{
// If (af. filterOK (line ))
// This. listBox1.Items. Add (line );
/// This. listView1.Items. Add (item );
//}
}
}
Int nc45 = 0;
Public void add2List (string line)
{
AccFilter4ihush af = new accFilter4ihush ();
If (af. filterOK (line ))
{
LoadRecNum ++;
// BeginInvoke
ListBox1.Invoke (new EventHandler (delegate
{
// Thread. Sleep (5000 );
This. listBox1.Items. Add (line );
// Console. WriteLine ("-- add2List:" + nc45.ToString () + ":" + line );
Nc45 ++;
}));
// Label8.Invoke (new EventHandler (delegate
//{
// Label8.Text = "loaded:" + loadRecNum. ToString ();
//}));
// Long nowtime = DateTime. Now. Ticks;
// Float span = (float) (nowtime-curtime)/(float) 10000000 ));
// Int spanint = (int) span;
// Label9.Invoke (new EventHandler (delegate
//{
// Label9.Text = "in use:" + spanint. ToString () + "seconds ";
//}));
}
// This. listView1.Items. Add (item );
}