Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:35:43+00:00 2026-06-13T02:35:43+00:00

Sorry if the title is not clear or correct, dont know what title should

  • 0

Sorry if the title is not clear or correct, dont know what title should i put. Please correct if wrong.
I have this code to download images from IP camera and it can download the images.
The problem is how can i do the images downloading process at the same time for all cameras if i have two or more cameras?

private void GetImage()
{
   string IP1 = "example.IPcam1.com:81/snapshot.cgi;
   string IP2 = "example.IPcam2.com:81/snapshot.cgi;
   .
   .
   .
   string IPn = "example.IPcamn.com:81/snapshot.cgi";

   for (int i = 0; i < 10; i++)
   {
       string ImagePath = Server.MapPath("~\\Videos\\liveRecording2\\") + string.Format("{0}", i, i + 1) + ".jpeg";
       string sourceURL = ip;
       WebRequest req = (WebRequest)WebRequest.Create(sourceURL);
       req.Credentials = new NetworkCredential("user", "password");
       WebResponse resp = req.GetResponse();
       Stream stream = resp.GetResponseStream();
       Bitmap bmp = (Bitmap)Bitmap.FromStream(stream);
       bmp.Save(ImagePath);
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:35:44+00:00Added an answer on June 13, 2026 at 2:35 am

    There are several methods that will depend on how you want to report feedback to the user. It all comes down to multi-threading.

    Here is one example, using the ThreadPool. Note that this is missing a bunch of error checking throughout… It is here as an example of how to use the ThreadPool, not as a robust application:

    private Dictionary<String, String> _cameras = new Dictionary<String, String> {
        { "http://example.IPcam1.com:81/snapshot.cgi", "/some/path/for/image1.jpg" },
        { "http://example.IPcam2.com:81/snapshot.cgi", "/some/other/path/image2.jpg" },
    };
    
    public void DoImageDownload() {
        int finished = 0;
    
        foreach (KeyValuePair<String, String> pair in _cameras) {
            ThreadPool.QueueUserWorkItem(delegate {
                BeginDownload(pair.Key, pair.Value);
                finished++;
            });
        }
    
        while (finished < _cameras.Count) {
            Thread.Sleep(1000);  // sleep 1 second
        }
    }
    
    private void BeginDownload(String src, String dest) {
        WebRequest req = (WebRequest) WebRequest.Create(src);
        req.Credentials = new NetworkCredential("username", "password");
        WebResponse resp = req.GetResponse();
        Stream input = resp.GetResponseStream();
        using (Stream output = File.Create(dest)) {
            input.CopyTo(output);
        }
    }
    

    This example simply takes the work you are doing in the for loop and off-loads it to the thread pool for processing. The DoImageDownload method will return very quickly, as it is not doing much actual work.

    Depending on your use case, you may need a mechanism to wait for the images to finish downloading from the caller of DoImageDownload. A common approach would be the use of event callbacks at the end of BeginDownload to notify when the download is complete. I have put a simple while loop here that will wait until the images finish… Of course, this needs error checking in case images are missing or the delegate never returns.

    Be sure to add your error checking throughout… Hopefully this gives you a place to start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all sorry for the title. I know this is not so clear
Sorry the title is not very clear. This is a follow up to my
Sorry the title may not be very clear. Basically I have a wrapper for
Sorry about the title to this question, it's not very clear but wasn't sure
Sorry if my title is not clear, I'm not sure how to word this.
Sorry if the title is not clear enough, I have <a> elements with the
Sorry, I wasn't sure exactly what title to give this and have not been
Sorry if the title is not enough clear, I didn't know how to write
Sorry for the title, perhaps it's not very clear. I have some SQL queries
Sorry if the title is not that specific, but I don't know how else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.