当前位置:编程学习 > asp >>

paip..net listbox性能极限

因为有个三十万行,6.5M的跑号器数据进行导入然后显示到LISTBOX……但是程序崩溃。。

 


我想可能是数据量太大。同时需要测试下LISTBOX的性能极限……就使用默认的  this.listBox1.Items.Add(line);这种方式

 


结果如下:
1千行数据:1秒
1万行:   3.5秒
10万行:   40秒

 


对于性能,我的要求是3.5秒内应该加载进LISTBOX....

 

 

 


---------------主要源码如下:-----------

 

 


    int loadRecNum = 0;
        long curtime = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDlg = new OpenFileDialog();
            openFileDlg.Title = "请选择:";
            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);


   &

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,