Is the WriteFile call properly synchronous, and can I delete the file written immediately after the call?
Is the WriteFile call properly synchronous, and can I delete the file written immediately
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is fully synchronous, as you can see by looking at the implementation of
HttpResponse.WriteFilewith Lutz Reflector. You can delete the file immediately after the call toResponse.WriteFile.You don’t have the guarantee that the response stream has been completely transmitted to the client, but calling
Response.Flushdoesn’t give you that guarantee either. So I don’t see a need to callResponse.Flushbefore deleting the file.Avoid loading the file into a
MemoryStream, it brings you no benefit, and has a cost in memory usage, especially for large files.