Delete a large number (>100K) of files with c# whilst maintaining performance in a web application?

前端 未结 10 2127
[愿得一人]
[愿得一人] 2020-12-30 04:40

I am trying to remove a large number of files from a location (by large I mean over 100000), whereby the action is initated from a web page. Obviously I cou

10条回答
  •  梦毁少年i
    2020-12-30 05:28

    Some improvements to speed it up in the back end:

    • Use Directory.EnumerateFiles(..) : this will iterate through files without waiting after all files have been retrieved.

    • Use Parallel.Foreach(..) : this will delete files simultaneously.

    It should be faster but apparently the HTTP request would still be timeout with the large number of files so the back end process should be executed in separate worker thread and notify result back to web client after finishing.

提交回复
热议问题