base {System.ApplicationException} = {"发生了异常“Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException”"}代码在线程中执行,开始已经设置了CheckForIllegalCrossThreadCalls = false;代码如下: //读取交流电表数据
cmd.CommandText = "select top 1 * from tabAcinfoRec order by RecDatetime Desc";
rd = cmd.ExecuteReader();
if (rd.Read())
{
foreach (Control l in this.Controls)
{
if (l.Tag != null)
{
if (Convert.ToString(l.Tag) == "l_AC")
{
// l.Text = string.Format("{0,9}", string.Format(Convert.ToSingle(rd[l.Name].ToString()).ToString("0.0")));
string s = string.Format("{0,10}", rd[l.Name].ToString());
//((Label)l).Text = "0";
l.Text = s;
//这里读取或设置Text值会发生 "base {System.ApplicationException} = {"发生了异常“Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException”"}" 错误
}
}
} }
rd.Close();
cmd.CommandText = "select top 1 * from tabAcinfoRec order by RecDatetime Desc";
rd = cmd.ExecuteReader();
if (rd.Read())
{
foreach (Control l in this.Controls)
{
if (l.Tag != null)
{
if (Convert.ToString(l.Tag) == "l_AC")
{
// l.Text = string.Format("{0,9}", string.Format(Convert.ToSingle(rd[l.Name].ToString()).ToString("0.0")));
string s = string.Format("{0,10}", rd[l.Name].ToString());
//((Label)l).Text = "0";
l.Text = s;
//这里读取或设置Text值会发生 "base {System.ApplicationException} = {"发生了异常“Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException”"}" 错误
}
}
} }
rd.Close();
你还是用标准方法Invoke一下吧
___________________________________
我写的vs2005源代码管理器
http://topic.csdn.net/u/20091203/10/ca40b678-5443-4a18-a9f6-fad9051d0797.html
Invoke我不会用,不知道怎么弄,谁能举个例子?
只要在线程里该一下窗口标题即可