我在调用New-Item以使用UNC路径在外部计算机上创建目录时看到了竞争条件.代码如下:
New-Item $target -itemType Directory -Force -Verbose | %{ Write-Host "Creating dir" $_.FullName }
之后立即使用Test-Path返回false.我把测试路径 – >睡眠1秒重试循环,睡眠1秒后,Test-Path返回true.
New-Item是阻止通话吗?我应该在打电话给New-Item后等待吗?
我无法重现你的问题.
PS > New-Item "test" -itemType Directory -Force -Verbose | %{ Test-Path $_.FullName } VERBOSE: Performing the operation "Create Directory" on target "Destination: C:\Users\Frode\Desktop\test". True
New-Item通过获取父目录的DirectoryInfo对象并将其调用为CreateSubDirectory来创建新目录,如:
DirectoryInfo subdirectory = new DirectoryInfo(parentPath).CreateSubdirectory(childName);
我不是开发人员,但AFAIK意味着它是一个阻塞调用,因为它等待一个DirectoryInfo对象作为回报.所以mabe的问题在于您的存储子系统.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。