如何复制具有取消副本能力的文件? [英] How to copy a file with the ability to cancel the copy?

查看:157
本文介绍了如何复制具有取消副本能力的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让程序取消副本。因此我不能使用 Microsoft.VisualBasic.FileIO.FileSystem.CopyFile
网上有一些 CopyFileEx 的包装,例如这里。但是,我宁愿不使用我不理解的东西,也不想要任何意外的结果(或错误)。有管理的方法吗?或者也许是MS的包装器(类似于Windows API CodePack)?

I’m trying to have the program be able to cancel the copy. Therefore I can’t use Microsoft.VisualBasic.FileIO.FileSystem.CopyFile . There are some wrappers for CopyFileEx on the web such as here. However, I rather not use something I don’t understand, not wanting any unexpected results (or bugs). Is there a managed way to do this? Or perhaps a wrapper by MS (in something like Windows API CodePack)?

谢谢。

推荐答案

以小块读取文件并将其写入目的地。定期检查是否要求您取消,如果检测到,请停止写入并关闭文件。

Read the file in small chunks and write it out to the destination. Periodically check whether you've been asked to cancel and if you detect that, stop writing and close the files.

这篇关于如何复制具有取消副本能力的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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