【发布时间】:2011-02-04 14:46:21
【问题描述】:
我的代码在强制运行时不会出现错误,我只是在尝试运行它时得到一个。它说 ThreadStateException 没有被我在多个地方搜索过的用户代码处理,我所有的代码看起来都以我知道问题所在的相同方式工作。这是不工作的代码
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FolderBrowserDialog dlg2 = new FolderBrowserDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
//do whatever with dlg.SelectedPath
{
DirectoryInfo source = new DirectoryInfo(dlg.SelectedPath);
DirectoryInfo target = new DirectoryInfo(dlg2.SelectedPath);
DirectoryInfo dir = new DirectoryInfo(dlg.SelectedPath);
FileInfo[] fis = dir.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo fi in fis)
{
if (fi.LastWriteTime.Date == DateTime.Today.Date)
{
File.Copy(fi.FullName, target.FullName +"\\"+ fi.Name, true);
}
}
}
}
任何帮助将不胜感激
【问题讨论】:
标签: c# button copy backgroundworker