删除的文件仍显示在Directory.GetFiles结果中

我有两个webmethods。 首先是:

void deleteFile(string filePath) { File.Delete(filePath); } 

另一个是:

 string[] getAllFile() { // at the same folder.... Directory.GetFiles("*.xml"); ..... return .... } 

我这样称呼这些方法:

 deleteFile("1.xml") getAllFile(); 

尽管删除了“1.xml”文件,但仍调用Directory.GetFiles("*.xml"); 仍会在结果中返回“1.xml”。 换句话说,它似乎没有被删除。

然后,当我循环结果时,尝试读取文件,获取FileNoFoundException

我发现DirectoryInfo / FileInfo类并不总是更新。 在这些情况下,您需要在目录/文件实例上调用Refresh方法。

我不知道,但我怀疑你的webmethods的结果是在某处缓存的。