日期:2014-05-16  浏览次数:21031 次

ASP.NET线程中更新UI控件
本帖最后由 u010242253 于 2014-04-01 21:24:12 编辑
最近在学习ASP.NET,遇到一个问题:在线程中无法更新UI控件,代码如下:
protected void Button4_Click(object sender, EventArgs e)
    {

        Thread thread = new Thread(new ThreadStart(dowork));
        thread.Start();
    }

   
       
      public void dowork() 
        {
            //Label1.Text = "开始线程";
            int st1;
            UInt32 Snr=0;
            StringBuilder Data1 = new StringBuilder(10);
            Data1.Length = 10;

           while(true)
            {
                
                st1 = Cdll.rf_srd_eeprom(icdev1, 0, 1, Data1);
                if (st1 != 0)
                {
                    Lab1.Text = "故障或为初始化";
                }
                else
                {
                    Lab1.Text = Data1.ToString();
                    st1 = Cdll.rf_reset(icdev1, 60);
                    st1 = Cdll.rf_card(icdev1, 1, ref Snr);
                    
                    if (st1 != 0)
                    {
                       Lab3.Text = "寻卡失败";
                       
                    }
                    else