c# - .NET Denying Access to Directories After Copy Operations -


i'm performing "safe" copy of directory on directory follows:

given source c:\source , target c:\target

  • copy c:\source c:\target-incoming
  • move c:\target (if exists) c:\target-outgoing
  • move c:\target-incoming c:\target
  • delete c:\target-outgoing (if exists)

if of first 3 steps fail, i'll attempt put things prevent data loss.

however, move of c:\target-incoming c:\target fails "access path c:\target-incoming denied" of time.

at moment, inserting thread.sleep(100) before move operation fixes problem me. however, waiting .1 of second seems ridiculous me. thread.sleep(10) isn't enough fix it. have sinking feeling value have wait depends on speed of disk io.

so, questions:

  • can prevent happening?
  • if not, there way of finding out when lock on directory released after copying it?

edit: clarity, i'm doing these operations in 1 method on 1 thread, , i'm using thread.sleep() pause code flow moment. moves , copies being done standard .net directory.move(), directory.createdirectory() , file.copyto() methods. appear .net methods returning before locks on respective files being released, causing necessity wait amount of time before continuing.

what happening thread trying "move c:\target-incoming c:\target" while "move c:\target c:\target-outgoing" not finished yet. track confirmed success of process after short thread sleep. try chain processes, i.e : divide each step specific methods, , call methods 1 after other (sync'ing start of method end of previous one) there various ways (among others syncing/locking/chaining different threads per process/step)

you check thread synchronization in .net

but of course, not possible cause problem.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -