网上的解决方案:http://blog.csdn.net/jumtre/article/details/44927271
1:设置 CheckForIllegalCrossThreadCalls false
2:委托
3:用BeginInvoke 或者异步线程
为什么我用了线程还是提示这个错误呢 不明白 看代码
void GetInstance_storeSelectChanged(object sender, StoreSelectChangedEventArgs e)
{
if (IsOk) return;
var temp=frmMain.GetInstance.dialog.Entity;;
if (temp == null || temp.Count == 0) return;
var sourceno = temp.Aggregate("", (current1, xxx) => current1 + (xxx.sourceno + ",")).TrimEnd(',');
Task.Factory.StartNew(() =>
{
var matappList = Voion.Core.SqlClientFactory.Instance.Query("SELECT * FROM matapp_dl WHERE docno=@docno", new { docno = sourceno });
if (matappList == null || matappList.Count == 0) return;
foreach (var tagetModel in matappList)
{
var outlist = new stotheroutlst_pro
{
zbid = tagetModel.zbid,
keyno = tagetModel.zbid,
code = tagetModel.proitemno,
productno = tagetModel.productno,
seqno = 0,
proitemno = tagetModel.proitemno,
appqty = 1,
numb = 2,
lostqty = tagetModel.lostqty,
sheetsqty = 3,
prosheetsqty = 4,
needqty = tagetModel.needqty,
needsheetqty = 5,
outno = "a",
active_id = 6,
stock_id = 7,
userid = User.Idno,
inputdate = DateTime.Now,
sizelost = 6,
retqty = tagetModel.Waitretqty,
appid = 100
};
Entity.StotherOutlstProList.Add(outlist);
}
bindingSource.ResetBindings(false);
var thread = new Thread(() =>
{
gridView1.RefreshData();
});
thread.Start();
});
IsOk = true;
}
错误的意思是 不是在UI线程修改了这个控件 。
GetInstance_storeSelectChanged是注册事件回调函数
报错的地方
gridView1.RefreshData(); 我已经用线程里面就是一个委托 怎么还是这个 错误呢。 不明白
1 回答
FFIVE
TA贡献1797条经验 获得超6个赞
method(T c,Action action) where T:Control
{
if(InvokeRequired)
{
Invoke(new Action(()=>action(c));
}
else
action(c);
}
bindingSource.ResetBindings(false);
method(gridView1,view=>view.RefreshData());
- 1 回答
- 0 关注
- 1481 浏览
添加回答
举报
0/150
提交
取消