private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; worker.ReportProgress(5); Cabinet cabinet = new Cabinet(); List <Object> list = e.Argument as List <Object>; int qty = (int)list[0]; int totalHeight = (int)list[1]; List <int> height = (List <int>)list[2]; int width = (int)list[3]; int depth = (int)list[4]; string angleColor = (string)list[5]; List <string> color = (List <string>)list[6]; List <string> door = (List <string>)list[7]; if (totalHeight > 375) { MessageBox.Show("You have exceeded the max height as it was shown under max height (red)"); MessageBox.Show("Please change the height of some boxes until actual height is green!"); } else { try { int nbr = qty + 1; if (qty >= 1) { //int progress = 100 / nbr * 1; worker.ReportProgress(100 / nbr * 1); cabinet.AddStorageBox(new CabinetFloor(height[0], width, depth, door[0], panelCol: color[0])); if (qty >= 2) { worker.ReportProgress(100 / nbr * 2); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[1], width, depth, door[1], panelCol: color[1])); if (qty >= 3) { worker.ReportProgress(100 / nbr * 3); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[2], width, depth, door[2], panelCol: color[2])); if (qty >= 4) { worker.ReportProgress(100 / nbr * 4); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[3], width, depth, door[3], panelCol: color[3])); if (qty >= 5) { worker.ReportProgress(100 / nbr * 5); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[4], width, depth, door[4], panelCol: color[4])); if (qty >= 6) { worker.ReportProgress(100 / nbr * 6); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[5], width, depth, door[5], panelCol: color[5])); if (qty >= 7) { worker.ReportProgress(100 / nbr * 7); incrementer(); cabinet.AddStorageBox(new CabinetFloor(height[6], width, depth, door[6], panelCol: color[6])); } } } } } } } worker.ReportProgress(100); cabinet.AddScratchAngles(angleColor); CartPage.Cart.AddToCart(cabinet); } catch (NullReferenceException) { MessageBox.Show("Please enter all the necessary information\n"); } } }