这一站幸福0412 2016-11-07 01:42 采纳率: 0%
浏览 717

线程池中的线程新建窗体无反应

主界面中有一个按钮,将按钮点击触发的处理事件写成了一个线程池调用的方式,
处理函数里面有新建一个窗体的功能,但是单步调试发现,当执行的窗体SHOW函数
的时候,线程就没反应了,请教下这是什么问题,请大神指点

 private void button1_Click_1(object sender, EventArgs e)
        {
           ThreadPool.QueueUserWorkItem(new WaitCallback(ReLoadScreenInfo));
        }

public void ReLoadScreenInfo(object state)
{
SettingInfo temp1 = this.setting.Clone();
using (Form4 form = new Form4(temp1))
{
DialogResult dr4 = form.ShowDialog(this);
if (dr4 == DialogResult.OK)
{
this.setting = temp1;
this.setting.Save();

                //更新界面
                dataGridView1.Rows.Clear();
                int cnt = 0;
                netConnectRecord.Clear();
                foreach (ConInfoElement element in this.setting.ScreenInfos)
                {
                    #region 设置netConnectRecord
                    NetConnectRecord _netconnectrecord = new NetConnectRecord();
                    string[] ipSet = element.Ip.Split('\\');
                    foreach (string ip in ipSet)
                    {
                        _netconnectrecord.IPCheckedResult.Add(ip, string.Empty);
                        _netconnectrecord.isIPChecked.Add(ip, false);
                        _netconnectrecord.isConnectOK.Add(ip, false);
                    }
                    //   _netconnectrecord.num = ipSet.Length;
                    netConnectRecord.Add(element.Id, _netconnectrecord);
                    #endregion
                    cnt++;
                    dataGridView1.Rows.Add(cnt.ToString(), element.Id, element.Ip, element.SiteName, global::HisenseLED.Properties.Resources.gray, "还未连接");
                }
                //MQ更新 
                mqConnect.ScreenInfoList = this.setting.ScreenInfos;
                //网络库更新IP列表
                jxqdNetComunicator.LoadClients(GetIPList(setting), 56000);
            }
        }

    }
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-11-07 02:50
    关注

    不能在非UI线程创建界面/操作界面,这是基本常识问题!

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?