FileStream not closing file

后端 未结 1 1990
误落风尘
误落风尘 2021-02-15 15:04

I have the following code:

using (MemoryStream str = new MemoryStream())
      {
             Program.api.GetDocument(result, str);
             using (FileStrea         


        
1条回答
  •  独厮守ぢ
    2021-02-15 16:06

    Your problem is most likely caused by Windows Search Indexing which is a part of Windows Search. If you attempt to access the file immediately (or very shortly) after modifying it, you may run into the sort of issues you are seeing. The best way around this is to add retry logic to the file operation you are performing, which waits some small period of times and re-attempts the file op.

    If you would like to confirm that the problem is cause by Windows File Search Indexing, you can disable it for the file type and/or location where you are writing your file to see if that makes the problem go away.

    0 讨论(0)
提交回复
热议问题