private void SendShipmentsAgentDoWork(object sender, DoWorkEventArgs e) { var sendShipmentsCount = 1; //Comprobar la configuraciĆ³n if (!ValidateConfiguration()) { return; } var pendingShipments = _myShipmentsManager.Pending(null); Dispatcher.BeginInvoke(new Action(() => { PgsBarShipments.Value = 0; PgsBarShipments.Maximum = pendingShipments.Count; })); //Enviar //Limpiamos log Log.Delete(); foreach (var shipmentsPendiente in _myShipmentsManager.Pending(null)) { _myShipmentsManager.Send(shipmentsPendiente); var interval = Convert.ToInt32(GlobalConfig.ShippingInterval) * 1000; var count = sendShipmentsCount; Dispatcher.BeginInvoke(new Action(() => { LblCountSendShipments.Content = count + "/" + pendingShipments.Count; PgsBarShipments.Value = PgsBarShipments.Value + 1; })); Thread.Sleep(interval); sendShipmentsCount += 1; } }