C# how to lock the file -


we using application reads file , inserts database. reason, set creation time particular time. , when create file application picks file before change creation time. there anyway can lock file until change creation time.

the error getting @ file.setcreationtime file being used other process or file archived.

//copy signal file s = filepath + "s"; news = targetfullpath2 + "s"; file.copy(s, news, true); // //new creation ts dtfilecreation = file.getcreationtime(s); //retain creation time file.setcreationtime(news, dtfilecreation); 

please advice.

the common solution create file (and set timestamp) in different directory or under different name first, , move or rename when it’s ready other process can pick up. move/rename atomic operation on ntfs (unless of course move files between separate partitions).

for example:

s = filepath + "s"; news = targetfullpath2 + "s"; file.copy(s, news + "_", true);    // add _ other process                                    // doesn’t “see” file yet  dtfilecreation = file.getcreationtime(s); file.setcreationtime(news + "_", dtfilecreation);  // we’re done file, rename intended final name file.move(news + "_", news); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -