我有點問題。我試圖製作一個表格,用狀態欄複製從A點到B點的東西。現在複製工作正常,但狀態欄只是沒有做任何事情.. 任何人有任何線索?複製進度條不起作用
public partial class Form4A : Form
{
public Form4A()
{
InitializeComponent();
OtherSettings();
BackgroundWorker.RunWorkerAsync(); // Starts wow copying
}
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
string SourcePath = RegistryRead.ReadOriginalPath();
string DestinationPath = RegistryRead.ReadNewPath();
if (!Directory.Exists(SourcePath))
{
for (int i = 1; i <= 100; i++)
{
//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
//Copy all the files
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath));
BackgroundWorker.ReportProgress(i);
}
}
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
}
確定的目標路徑已不存在,你調用這個函數之前?此外,它看起來像你沒有正確呈現進度更新,而是你複製100次所有文件。 –
它應該'如果(Directory.Exists(SourcePath))'沒有「!」。 –