Please visit my new Web Site https://coderstechzone.com
In most of the cases specially in image manipulation time developers faced an error like:
The process cannot access the file because it is being used by another process.
The error happened because when you try to access an object of image or Font just immediately after you use it. Because the dot net framework does not destroy the resource before you calling. To resolve this problem you have to release the resource first & then you can use it again. To ensure freeing the unmanaged resource is a tough job but doable.
Asp.net provides us "using" statement to wrap up your respective code within using statement. This statement ensure that the object will be destroyed just after its scope even if any error occured within the block. So the solution is when you want to manipulate any image type object or Font or any file then wrap up all code within the using statement. The sample format is given below:
using (System.Drawing.Image Img = System.Drawing.Image.FromFile(Server.MapPath("Images\\YourImageName.jpg"))) { // Do whatever you want }
So it would be better to practice always wrap up your relevant code within "Using" statement.
0 comments:
I WOULD BE DELIGHTED TO HEAR FROM YOU