我什么时候可以Response.WriteFile使用后删除文件()? [英] When can I delete a file after using it in Response.WriteFile()?

查看:92
本文介绍了我什么时候可以Response.WriteFile使用后删除文件()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是WriteFile的调用适当的同步,我可以删除通话后立即写入的文件?

Is the WriteFile call properly synchronous, and can I delete the file written immediately after the call?

推荐答案

这是完全同步的,你可以通过查看的Htt presponse.WriteFile 与卢茨反射。您可以在调用 Response.WriteFile 后,立即删除该文件。

It is fully synchronous, as you can see by looking at the implementation of HttpResponse.WriteFile with Lutz Reflector. You can delete the file immediately after the call to Response.WriteFile.

您不具备保证响应流已经完全传输到客户端,但调用 Response.Flush 不给你,在保证。所以,我不认为有必要呼吁 Response.Flush 之前删除的文件。

You don't have the guarantee that the response stream has been completely transmitted to the client, but calling Response.Flush doesn't give you that guarantee either. So I don't see a need to call Response.Flush before deleting the file.

避免加载文件到的MemoryStream ,它给你带来任何好处,并且在内存使用成本,特别是对于大型文件。

Avoid loading the file into a MemoryStream, it brings you no benefit, and has a cost in memory usage, especially for large files.

这篇关于我什么时候可以Response.WriteFile使用后删除文件()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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