SAVING IMAGE FILES IN SERVER AFTER RESPONSE

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
C# 
 1512  View(s)
Ratings:
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!
  1. Pravesh Singh

    Post:101

    Points:709
    Re: Saving Image files in server after response

    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);

        });

  1. Mark Devid

    Post:102

    Points:714
    Re: Saving Image files in server after response

    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();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!