简体   繁体   English

何时使用PInoke? -PInvoke CopyFile与File.Copy

[英]When to use PInoke? - PInvoke CopyFile versus File.Copy

What advantages and disadvantages have each side? 双方各有什么优缺点?

As far as I am concerned PInvoke is faster and also has no problems with long paths? 就我而言,PInvoke更快,并且在长路径上也没有问题吗? So if I have to copy large file structures eg terabytes of data and thousands of folders / files, I should use PInvoke? 因此,如果我必须复制大型文件结构(例如,TB级数据和数千个文件夹/文件),我应该使用PInvoke吗?

eg if you want to copy large file-structures from/to shares and retain permissions. 例如,如果您要从共享复制大型文件结构到共享并保留权限。

There is no need to use PInvoke here, since File.Copy itself calls the Windows CopyFile function already . 这里不需要使用PInvoke,因为File.Copy本身已经调用了Windows CopyFile函数

The file path length is already resolved since .NET 4.6.2. 自.NET 4.6.2起,文件路径长度已解决。 See this blog where it describes the app switch you need to set in your app.config . 请参阅此博客 ,其中描述了您需要在app.config设置的应用程序开关。

The only thing the .NET Framework does is some additional checks and error handling, as you can see in the referenced source code. .NET Framework唯一要做的就是一些附加的检查和错误处理,如您在所引用的源代码中所见。 Nothing less, nothing more. 什么都没有,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM