好的,所以我有以下代码:
public partial class Form1 : Form
{
private void FileWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
ListViewItem newFile = new ListViewItem(new string[] { e.FullPath.ToString(), e.ChangeType.ToString() }, -1);
newFile.Tag = e.FullPath.ToString();
FileList.Items.Add(newFile);
}
private void CopyButton_Click(object sender, EventArgs e)
{
BackgroundWorker backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.ProgressChanged +=
new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
int TotalFiles = FileList.CheckedItems.Count;;
int CurrentFile = 1;
foreach (ListViewItem CheckedFile in FileList.CheckedItems)
{
backgroundWorker1.ReportProgress((CurrentFile / TotalFiles) * 100);
string FileBuilder = Settings.Default.Destination + Path.GetFileName(CheckedFile.Tag.ToString());
if (File.Exists(FileBuilder) == false)
{
File.Copy(CheckedFile.Tag.ToString(), FileBuilder);
}
CurrentFile++;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
CopyProgressBar.Value = e.ProgressPercentage;
}
}
它一直告诉我DoWork事件中的报告进度方法在当前上下文中不存在,有人知道为什么吗?如果这是一个菜鸟错误,请原谅我,我是新人。