Is it possible to use a lock on one xml file that can potentially be written to from multiple aspx pages at the same time? I'm asking because MSDN suggest that the lock stat开发者_开发问答ement should be used with a private static object instance as the expression, and since there are multiple pages involved i guess i can't use the same object on all the pages?
You can use the File.Open
overload that takes a FileShare
enum that is set to None
. No other thread will be able to open the file until closed.
FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
This piece of code will open the (existing) file specified in the path
argument, for reading and without any sharing.
精彩评论