private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { List <SMSBAL> sms_list = e.Argument as List <SMSBAL>;//0 message, 1 phoneNo, 2 sms_id,3 status foreach (var item in sms_list) { bool IsSend = false; SMS sms = new SMS(); foreach (var port in sms.GetConnectedPort()) { if (sms.SendSMS(port, item.Message, item.phoneNo)) { //message send //MessageBox.Show("Message Sended"); var resend_list = resend_db.LoadAll().Where(m => m.sms_id == item.sms_id).ToList(); foreach (var item1 in resend_list) { resend_db.Delete(item1); } SMSBAL sms_single = sms_db.LoadAll().Where(m => m.sms_id == item.sms_id).SingleOrDefault(); sms_single.Message = item.Message; sms_single.phoneNo = item.phoneNo; sms_single.IsDelieverd = true; sms_single.IsSeen = true; sms_db.Update(sms_single); IsSend = true; break; } } if (!IsSend) { ResendBAL resend = new ResendBAL(); resend.sms_id = Convert.ToInt32(item.sms_id); resend_db.Add(resend); //Message not Send // MessageBox.Show("Message not Sended"); } } }