c# - File is being used by another process on generating thumbnail -


i'm working on file manager project. need generate thumbnail if file of image type. i'm able using ihttphandler method

  sytem.drawing.image.getthumbnailimage(), 

here code

hashtable ht;             ht = new hashtable();             using (filestream finfo = new filestream(context.server.mappath(url), filemode.open))             {                 byte[] bfile;                 bfile = generatethumbnail(finfo, xlen, ylen);                 ht.add(id, bfile);                 finfo.close();                  byte[] arrimg = (byte[])ht[id];                 context.response.clear();                 context.response.contenttype = "image/jpeg";                 context.response.binarywrite(arrimg);                 context.response.end();             }     private byte[] generatethumbnail(stream fstream, string xlen, string ylen)     {         using (image img = image.fromstream(fstream))         {             image thumbnailimage = img.getthumbnailimage(int.parse(xlen), int.parse(ylen), new image.getthumbnailimageabort(thumbnailcallback), intptr.zero);              using (memorystream imagestream = new memorystream())             {                 thumbnailimage.save(imagestream,system.drawing.imaging.imageformat.jpeg);                  byte[] imagecontent = new byte[imagestream.length];                 imagestream.position = 0;                 imagestream.read(imagecontent, 0, (int)imagestream.length);                 return imagecontent;             }         }     } 

problem

newly uploaded file on genrating thumb throwing expection : being used process, after sometime shows thumbnail. q. im missing close stream ?


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -