I am having a problem where the bitmap image that I just created and saved
to disk can not be found but the code in another area of the program. When I
reattempt to access the same image, it always works becuase the image has
been fully saved to that drive by that time. Is there a way to make sure
that a newly created bitmap image is phisically saved to disk before it is

The code that creates that new bitmap image is as follows

Bitmap ImageOut = new Bitmap(NewImageWidth, NewImageHeight);

//other code

ImageOut.Save(NewImagePhisicalPath, FileFormat);

The code that tries to access the new bitmap looks like this

System.Drawing.Image image =
System.Drawing.Image.FromFile(NewImagePhisicalPath );

But this fails some of the time with a file not found execption.

I can add the follow code that should fix this but I am wondering if there
is a better way to flush the file to the disk before accessing it?

while (!(File.Exists(NewImagePhisicalPath)))


//do nothing


string ImageName =
System.Web.HttpContext.Current.Request.MapPath(Pho toImageButton.ImageUrl);