'Cant Update Image in a quick succession

I'm doing a simple code to update profile pics, by saving uploaded file into a folder and processing its required versions using Bitmap.

Issue is that i cant change image in quick succession, After changing once, it shows file is being used by another process. It works after logging out and logging in again.

fuPic.SaveAs(Server.MapPath("/assets/user_images_raw/" + Session["userid"].ToString() + ".jpg"));
flag = "yes";
                        
Bitmap map = new Bitmap(System.Drawing.Image.FromFile(Server.MapPath("/assets/user_images_raw/" + Session["userid"].ToString() + ".jpg")), new Size(60, 60));
map.Save(Server.MapPath("/assets/user_images/" + Session["userid"].ToString() + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
map.Dispose();
                        
Bitmap map_2 = new Bitmap(System.Drawing.Image.FromFile(Server.MapPath("/assets/user_images_raw/" + Session["userid"].ToString() + ".jpg")), new Size(125, 125));
map_2.Save(Server.MapPath("/assets/user_thumbnails/" + Session["userid"].ToString() + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
map_2.Dispose();

What am i missing ?

Edit: I'm not seeing any issue at localhost. Its just after hosting on IIS.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source