我有一段代码,有时会抛出IOException,在它的信息中写着The file is used by another process,对我来说一点意义都没有。我真的很困惑。据我所知,目录不是需要处理的跨线程操作或诸如此类的资源。
void CloudFolderWatcher_Created ( object sender, FileSystemEventArgs e )
{
var foldersToCreate = Directory.GetDirectories(e.FullPath, "*", SearchOption.AllDirectories);
/// do something with foldersToCreate
}这里可能有什么问题?我怎样才能克服这个问题?
发布于 2014-01-30 09:38:17
这意味着某些其他进程(甚至您的进程)在某个目录上持有一个锁,从而阻止您的进程枚举其内容。
发布于 2014-01-30 09:33:31
FileSystemEventArgs背后一定有问题,因为其他的都在工作。(假设您使用WFA)。
把(A)略高于公共form1()
您将查看foldersToCreate变量下的所有目录。检查你的"e“论点
(A)
public string Mypath;
private void Form1_Load(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
Mypath = folderBrowserDialog1.SelectedPath;
if (Mypath != "")
CheckFOlder();
}
private void CheckFOlder()
{
try
{
var foldersToCreate = Directory.GetDirectories(Mypath, "*", SearchOption.AllDirectories);
}
catch (IOException e)
{
MessageBox.Show(e.Message.ToString());
}
catch (UnauthorizedAccessException e)
{
MessageBox.Show(e.Message.ToString());
}
}必须在表单folderBrowserDialog1中添加PS
https://stackoverflow.com/questions/21451156
复制相似问题