0
基本上,我擁有的是一個後臺工作者。一個按鈕被點擊和按鈕有BackgroundWorker.DoWork的DoWork的溫控功能具有此代碼:For Loop Inside BackgroundWorker.DoWork
For Each item In lst_Folders.CheckedItems
Dim path As String = My.Settings.stng_sourceDirectory + "\" + item.Text
For Each dirPath As String In Directory.GetDirectories(path, "*", SearchOption.AllDirectories)
Directory.CreateDirectory(dirPath.Replace(path, My.Settings.stng_saveDirectory + "\" + item.Text))
Next
'Copy all the files & Replaces any files with the same name
For Each newPath As String In Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
File.Copy(newPath, newPath.Replace(path, My.Settings.stng_saveDirectory + "\" + item.Text), True)
Next
Next
它基本上是複製和粘貼的目錄,這取決於ListViewItem的檢查。問題是,當我按一下按鈕,背景的工作,但我立刻得到一個錯誤說
Cross-thread operation not valid: Control 'lst_Folders' accessed from a thread other than the thread it was created on.
可有人請這個問題幫助我。我只是不知道爲什麼它不會工作。