Directory.Delete()/.Create()是否同步? [英] Is Directory.Delete() / .Create() synchronous?

查看:35
本文介绍了Directory.Delete()/.Create()是否同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System.IO;
Directory.Delete("someFolder",true);
Directory.Create("someFolder");

在删除目录之后还是在删除目录时,将执行第三行吗?我是否必须将第一个命令放入任务"并等待其完成?

Will the third line be executed after the dir was deleted or while the directory is being deleted? Do I have to put the first command into a "Task" and wait until it is finished?

推荐答案

这是一个较旧的问题,但值得注意- Directory.Delete 最终会调用Windows的 RemoveDirectory 函数,哪个标记为要删除的目录,但是在关闭所有文件句柄之前,文件系统不会实际上将其删除(

This is an older question but worth noting - Directory.Delete ultimately calls the RemoveDirectory Windows function, which marks the directory as to-be-deleted, but the filesystem won't actually delete it until all file handles are closed (see docs). As a result it is perfectly possible to return from Directory.Delete and find the directory still exists.

这篇关于Directory.Delete()/.Create()是否同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆