Using Directory.Delete() and Directory.CreateDirectory() to overwrite a folder

后端 未结 3 1759
走了就别回头了
走了就别回头了 2021-01-01 23:29

In my WebApi action method, I want to create/over-write a folder using this code:

string myDir = \"...\";
if(Directory.Exists(myDir)) 
{
    Dir         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-02 00:28

    Sounds like race condition to me. Not sure why - you did not provide enough details - but what you can do is to wrap everything in lock() statement and see if the problem is gone. For sure this is not production-ready solution, it is only a quick way to check. If it's indeed a race condition - you need to rethink your approach of rewriting folders. May be create "GUID" folder and when done - update DB with the most recent GUID to point to the most recent folder?..

提交回复
热议问题