为什么在.net中没有异步文件删除? [英] Why isn't there an asynchronous file delete in .net?

查看:100
本文介绍了为什么在.net中没有异步文件删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你有异步版本的读写(开始/结束函数),但不是删除(我可以告诉)。这有什么理由吗?是不是有很多理由异步删除读/写?

使用线程来模拟异步行为不同于异步函数。巨大的差异,确保你得到了理解的并行处理,但它并不真正阻止阻塞,其他线程仍然阻塞等待文件I / O完成。真正的异步函数(开始/结束函数)在系统级别运行,它们排队文件I / O,让应用程序继续,让应用程序知道何时准备好继续文件I / O(允许你当你等待文件I / O时,做其他事情)。

解决方案

这会很有用。如果在断开的网络共享上删除,DeleteFile最多可能需要30秒。



原因可能是没有本机函数异步删除文件。托管的API通常是非托管API的包装。


You have the asynchronous versions of read and write (begin/end functions), but not of delete (that I can tell). Is there any reason for this? Isn't there as much reason to do delete asynchronously as read/write?

Using threading to simulate asynchronous behavior is not the same as asynchronous functions. Big difference, sure you get the perceived parallel processing, but it's not really preventing blocking, that other thread is still blocked waiting for the file i/o to complete. The real asynchronous functions (begin/end functions) operate at a system level, they queue up file i/o, let the application proceed, and let the application know when it is ready to proceed with the file i/o (allowing you to do other things while you wait for the file i/o to come available).

解决方案

This would be useful. DeleteFile could take up to 30s if deleting on a disconnected network share.

The reason is likely to be that there is no native function to delete a file asynchronously. The managed APIs generally are wrappers around the unmanaged ones.

这篇关于为什么在.net中没有异步文件删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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