Home > DeveloperSection > Forums > Saving Image files in server after response
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    December-18-2014 10:12 PM

 ASP.Net C# 
Ratings:


 2 Reply(s)
 1174  View(s)
Rate this:

My asp.net application saving a long list of image files and then have to view one of them. The client can browse the images, But its take a long time. I have a dictionary with key - file path and value -Image:

 

Dictionary<string, System.Drawing.Image> imageList = new Dictionary<string,System.Drawing.Image>();

 

//filling imageList

foreach (KeyValuePair<imagePath, System.Drawing.Image> item in imageList)

{

    item.Value.Save(item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);

}

I am looking for some way to save just one image file, make response, and continue saving the other image files, there is any way to do it? maybe with Thread? Thanks!


Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    December-19-2014 1:43 AM

Disk IO may be very slow, nevertheless you can try this

 

foreach (KeyValuePair<string, System.Drawing.Image> item in imageList)

    Task.Factory.StartNew(() =>

    {

        lock (item.Value)

            item.Value.Save(item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);

    });


Mark Devid
Mark Devid

Total Post:102

Points:714
Posted on    December-19-2014 6:42 AM

I put the images saving in thread block and it works perfectly and fast:

 

Dictionary<string, System.Drawing.Image> imageList = new Dictionary<string,System.Drawing.Image>();

 

//filling imageList

 

Thread thread = new Thread(() =>

{

   foreach (KeyValuePair<string, System.Drawing.Image> image in imageList)

    {

       image.Value.Save(item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);

    }

});

thread.Start();


Don't want to miss updates? Please click the below button!

Follow MindStick