要对两个数据库进行大量的操作,当按下一个"开始"按钮后,就开始操作,由于数据量很大,我在操作过程中要求显示一些信息,就是操作到哪个表了之类的信息在listBox上,但一按下开始,并不是如我所愿,不是把信息一项项显出来,而是处在一种假死状态,要等处理完所有事情后才显示所有应该提示的信息,有什么方法可以解决这个问题吗?
相关代码如下:int i=0;   //记数器
private void button1_Click(object sender, System.EventArgs e)
 {   ....   OdbcDataReader thisReader=thisCommand.ExecuteReader();
   while (thisReader.Read())  //循环读取数据集的每一条记录,并做处理
    {
     i++;
     string cyhcln="记录数:"+"  "+i.ToString();
     listBox1.Items.Add(cyhcln);
     .....
     .....
    }    thisReader.Close();
}我目的是想在listBox1中显示已经处理的记录数,实时的显示,但程序就在所有处理完后才一次显示出来.

解决方案 »

  1.   

    private void button1_Click(object sender, System.EventArgs e)
     {   ....
       int i=0;   //记数器   OdbcDataReader thisReader=thisCommand.ExecuteReader();
       while (thisReader.Read())  //循环读取数据集的每一条记录,并做处理
        {
         i++;
         string cyhcln="记录数:"+"  "+i.ToString();
         listBox1.Items.Add(cyhcln);
         .....
         .....
        }    thisReader.Close();
    }
      

  2.   

    private void button1_Click(object sender, System.EventArgs e)
     {   ....
       int i=0;   //记数器   OdbcDataReader thisReader=thisCommand.ExecuteReader();
       listBox1.Items.Add("正在处理xxx表...);
       while (thisReader.Read())  //循环读取数据集的每一条记录,并做处理
        {
         i++;
         string cyhcln="记录数:"+"  "+i.ToString();
         listBox1.Items.Add(cyhcln);
         .....
         .....
        }    thisReader.Close();
    }
      

  3.   

    以前做ASP的时候可以在IFRAME里面做数据操作,操作一个就更新前台HTML数据来实现。ASP.NET应该也可以,如果用线程,感觉太复杂了点
      

  4.   

    适当的地方加一句Application.DoEvents()让它更新页面
      

  5.   

    利用多线程,msdn上有相关技术文档
    http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/misMultithreading.mspx
      

  6.   

    现在我选择用多线程处理
    给分了...thank 各位
      

  7.   

    每次listBox1.Items.Add(cyhcln);
    之后马上作一次listBox1.Refresh();
    就可以