網上的解決方案: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 關注
- 1535 瀏覽
添加回答
舉報
0/150
提交
取消