thUpdataCInfo = new Thread(new ThreadStart(LoadCInfo));
thUpdataCInfo.Start();
private void LoadCInfo()
{
this.BeginInvoke(new delegateLoadDataC(LoadCInfoData));
}
private void LoadCInfoData()
{
UpdataCInfo();
}
private void UpdataCInfo()
{
while (true)
{
if (GlobleDate.m_databufffc.TagList.Count > 0)
{
TagListBuff templist;
templist = GlobleDate.m_databufffc.Clone() as TagListBuff;
GlobleDate.m_databufffc.Clear();
for (int i = 0; i<templist.TagList.Count;i++ )
{
for (int j = 0; j < m_ptn.Count;j++ )
{
if (templist.TagList[i].Equals(m_ptn[j].m_strFCCode))
{
Mypanel1 pa = new Mypanel1();
pa.Location = new Point(7, 10 + (plScanList.Controls.Count - 1) * (pa.Height + 5) + (pa.Height + 5));
pa.LbShelf = m_ptn[j].m_strFCCode;
pa.LbDetail = m_ptn[j].m_strFCNumScan + "/" + m_ptn[j].m_strFCNun;
plScanList.Controls.Add(pa);
}
}
}
}
else
{
GlobleDate.userWaitor6.WaitOne();
}
}
}
如果把这个给注释了 this.BeginInvoke(new delegateLoadDataC(LoadCInfoData)); 窗口的控件就可以响应事件了 为什么???
plScanList.是一个控件
主要是当扫描到一个满足条件的 就会在 plScanList.上自动增加一个panel (主要功能)
------解决思路----------------------
System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(UpdataCInfo);
task.Start();
private void UpdataCInfo()
{
Action async;
while (true)
{
if (GlobleDate.m_databufffc.TagList.Count > 0)
{
TagListBuff templist;
templist = GlobleDate.m_databufffc.Clone() as TagListBuff;
GlobleDate.m_databufffc.Clear();
for (int i = 0; i<templist.TagList.Count;i++ )
{
for (int j = 0; j < m_ptn.Count;j++ )
{
if (templist.TagList[i].Equals(m_ptn[j].m_strFCCode))
{
Mypanel1 pa = new Mypanel1();
pa.Location = new Point(7, 10 + (plScanList.Controls.Count - 1) * (pa.Height + 5) + (pa.Height + 5));
pa.LbShelf = m_ptn[j].m_strFCCode;
pa.LbDetail = m_ptn[j].m_strFCNumScan + "/" + m_ptn[j].m_strFCNun;
async = () => { plScanList.Controls.Add(pa);};
this.Invoke(async);
}
}
}
}
else
{
GlobleDate.userWaitor6.WaitOne();
}
}
}
------解决思路----------------------
楼主,我想表达的意思跟这位同志是一样的;你把代码改成我那样还是不行吗?