我想從另一個類填充列表視圖,但我geting此錯誤: 「跨線程操作無效:控制'listView1'從一個線程以外的線程訪問它被創造的「填充從另一個線程的列表視圖
在我的課堂我宣佈我的列表視圖這樣的:
class CheckBlankPages
{
public String[] pdfFiles
{ get; set; }
ListView _ListVireRef;
public int NrCRT = 1;
public CheckBlankPages(String[] pdfFiles = null, ListView listView = null)
{
this.pdfFiles = pdfFiles;
_ListVireRef = listView;
}
public void StartCheckingPDF()
{
foreach (string pdf in pdfFiles)
{
String[] itm = { (NrCRT++).ToString(), pdf };
ListViewItem item = new ListViewItem(itm);
_ListVireRef.Items.Add(item);
}
}
}
,在我的MainForm我用這個代碼:
DialogResult rezultat = openFileDialog1.ShowDialog();
if (rezultat == DialogResult.OK)
{
CheckBlankPages ck = new CheckBlankPages(openFileDialog1.FileNames, listView1);
Thread CheckPDFs = new Thread(new ThreadStart(ck.StartCheckingPDF));
CheckPDFs.Start();
}
什麼是WR翁?
[Cross-thread operation not valid:從其創建線程以外的線程訪問的控件]的可能副本(http://stackoverflow.com/questions/142003/cross-thread-operation-not-valid -control-accessible-from-a-thread-other-the- – quetzalcoatl 2017-02-07 13:25:29