c# - the process cannot access the file as its being used by another process -


have been struggling error ages. below code question

        ( int32 counter = 0; counter < x.rows.count; counter++)         {             using (filestream bitmapfile = new filestream(@"c:/someolddir/file1.txt", filemode.open, fileaccess.read, fileshare.readwrite))             {                 using (bitmap uploadedbitmap = new bitmap(bitmapfile))                 {                     using (system.drawing.image uploadedbitmapresized = extensionhelpers.resize(uploadedbitmap, 800, 600, rotatefliptype.rotatenoneflipnone))                     {                         uploadedbitmapresized.save(@"c:/somenewdir/file1.txt",system.drawing.imaging.imageformat.jpeg);                     }                 }             }            /*errror occurss on line */              file.setcreationtime(@"c:/somenewdir/file1.txt",somedatetimevariable);          } 

the problem having code works fine first 30 or 40 images in collection when 50 or 60 error saying file trying set date-time being used process. error occurs when iterating through large collection , @ 40 or 50th position in iteration how can first 30 images work fine , of sudden file locked process. have in using statements error still persists.

do have how wait until file saved before accessing shouldn't case since saving file first , trying access it. wrong code?

i cannot find now, remember 1 of previous projects use of using in case doesn't work.

so, drop of usings , manage file closing manually.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -