private void backgroundWorkerImagePath_DoWork(object sender, DoWorkEventArgs e) { // simulate progress 1% ~ 10% for (int i = 1; i <= 10; i++) { Thread.Sleep(25); backgroundWorkerImagePath.ReportProgress(i); } // get the sku text and initilize sku field sku = skuCodeTextbox.Text; // search images and generate uri that assign to image fields int index = 0; string[] imageCopy = ImageSearch.GetImageUri(sku); foreach (string uri in imageCopy) { if (index > 9) { break; } image[index] = uri; index++; } // add the missing value for (int i = index; i < 10; i++) { image[i] = string.Empty; } index = 0; string[] groupCopy = ImageSearch.GetGroupUri(sku); foreach (string uri in groupCopy) // get the value that exist { if (index > 4) { break; } group[index] = uri; index++; } // add the missing value for (int i = index; i < 5; i++) { group[i] = string.Empty; } index = 0; string[] modelCopy = ImageSearch.GetModelUri(sku); foreach (string uri in modelCopy) // get the value that exist { if (index > 4) { break; } model[index] = uri; index++; } // add the missing value for (int i = index; i < 5; i++) { model[i] = string.Empty; } index = 0; string[] templateCopy = ImageSearch.GetTemplateUri(sku); foreach (string uri in templateCopy) // get the value that exist { if (index > 1) { break; } template[index] = uri; index++; } // add the missing value for (int i = index; i < 2; i++) { template[i] = string.Empty; } // simulate progress 10% ~ 20% for (int i = 10; i <= 20; i++) { Thread.Sleep(25); backgroundWorkerImagePath.ReportProgress(i); } // addition fields for adding upc image upcCode9 = Upc.GetUpc(); upcCode10 = Upc.GetUpc10(upcCode9); // adding upc image ImageReplace imageReplace = new ImageReplace(); imageReplace.AddUpc(sku, upcCode9); imageReplace.AddUpc(sku, upcCode10); // assign textboxes to textbox holders imageTextbox[0] = image1Textbox; imageTextbox[1] = image2Textbox; imageTextbox[2] = image3Textbox; imageTextbox[3] = image4Textbox; imageTextbox[4] = image5Textbox; imageTextbox[5] = image6Textbox; imageTextbox[6] = image7Textbox; imageTextbox[7] = image8Textbox; imageTextbox[8] = image9Textbox; imageTextbox[9] = image10Textbox; groupTextbox[0] = group1Textbox; groupTextbox[1] = group2Textbox; groupTextbox[2] = group3Textbox; groupTextbox[3] = group4Textbox; groupTextbox[4] = group5Textbox; modelTextbox[0] = model1Textbox; modelTextbox[1] = model2Textbox; modelTextbox[2] = model3Textbox; modelTextbox[3] = model4Textbox; modelTextbox[4] = model5Textbox; templateTextbox[0] = template1Textbox; templateTextbox[1] = template2Textbox; // simulate progress 20% ~ 30% for (int i = 20; i <= 30; i++) { Thread.Sleep(25); backgroundWorkerImagePath.ReportProgress(i); } }