Thursday, 15 September 2011

c# - Best way (best performance) to lock file creation -



c# - Best way (best performance) to lock file creation -

i have web application homecoming images frontend. in application happens is: when request made particular image application checks if image exists on disk, if exists returns image. problem starts when image not exist on disk. when 2 requests made @ same time same image , not exist on disk have problem because 2 threads seek create same file on disk @ same time. solve problem, start tried create mutex in creation of disk image. had problem. server load enormous due big number of simultaneous requests server crash.

i inquire ideas solve problem. or if otherwise?

thank you.

you seek next pattern:

try read image (if succeeds, done) try create image write lock only on "file in utilize exception", little delay (milliseconds) go step 1 (retry)

make delay small, tiny bit larger time should need create image. implement retry limit, max 3 times or so.

this allow create utilize of existing (file) locking mechanism

c# multithreading thread-safety

No comments:

Post a Comment