Search code examples
c#winformsoracle11gdevexpressgsmcomm

Bulk SMS application hang when sent for many SMS


i have created simple application to bulk sms using GsmComm library , Oracle database and Devexpress. I sent message for many messages (more than 25 messages) my application got hang. i assume it because of too many process. the scenario, when a user sent message it will store to database (OUTBOX table), then user click button on outbox form, if message success to sent it will store to database (SENTMESSAGE table) and delete message where sent success in the OUTBOX table. when the message is processing to sent user couldn't click for another button or menu, but after it finished to sent ,application got normal again and user could click for many menus. i read some articles that it possible if used Gammu because it is third party application and can run as service to send and receive message, but i need it in gsmcomm library.

for detail, this my codes:

//SEND BULK SMS MORE THAN 30 MESSAGE APPLICATION HANG
if (CommSetting.comm.IsConnected() == true)
{
    int i;
    for (i = 0; i < gridView1.DataRowCount; i++)
    {
        string pesan = gridView1.GetRowCellValue(i,"MESSAGE").ToString();
        string ttd = lblTandaTangan.Text;
        string msg = pesan + Environment.NewLine + Environment.NewLine + ttd;  //SENT MESSAGE USING SIGNATURE

    var listPhoneNumber = new List<string>();
    listPhoneNumber.Add(gridView1.GetRowCellValue(i, "PHONENUMBER").ToString());

    foreach (var phoneNumber in listPhoneNumber)
    {
        var pdu = new SmsSubmitPdu(msg, phoneNumber, string.Empty);
        CommSetting.comm.SendMessage(pdu);

        //---------------STORE TO ORACLE DB--------------------
        if (koneksi_manual.con.State == ConnectionState.Open)
        {
            koneksi_manual.con.Close();
        }
        koneksi_manual.con.Open();

        OracleCommand cmd = new OracleCommand();
        cmd.CommandText = @"INSERT INTO MESSAGESENT (ID, DATE, TIME, PHONENUMBER, MESSAGE) VALUES 
                        (SQ_MESSAGESENT.NEXTVAL, '" + DateTime.Now + "', TO_DATE('" + DateTime.Now + "', 'dd/MM/yyyy hh24:mi:ss'), '"
                            + gridView1.GetRowCellValue(i, "PHONENUMBER") + "', '" + pesan.Replace("'", "''") + "', '" + Program.IDUser + "')";// <= Use gridView1.GetRowCellValue to get the cell value.
        cmd.Connection = koneksi_manual.con;
        cmd.ExecuteNonQuery();

        //Sleeps system for 1000ms for refreshing GSM Modem
        System.Threading.Thread.Sleep(1000);

        //DELETE MESSAGE SENT FROM OUTBOX
        var obj = gridView1.GetRowCellValue(i, "ID");

        OracleCommand cmd2 = new OracleCommand();
        cmd2.CommandText = "DELETE FROM OUTBOX WHERE ID = '" + obj + "'";
        cmd2.Connection = koneksi_manual.con;
        cmd2.ExecuteNonQuery();
    }
    MessageBox.Show("Message Sent", "Notif");
  }
}

I want users to be able click for another menu in my application when user is sending messages. i don't know how to solve this, perhaps anybody can giving me a suggest and any concept, i will really appreciate this. Thanks..


Solution

  • hi try to use threading over here

    Control.CheckForIllegalCrossThreadCalls = false;
     Private Void BtnSend_Click(Object Sender,EventArg e)
        {
          Thread th = new Thread(new ThreadStart(SendMSM));
        }
    
    
    
     Private void SendMSM()
        {
        if (CommSetting.comm.IsConnected() == true)
        {
            int i;
            for (i = 0; i < gridView1.DataRowCount; i++)
            {
                string pesan = gridView1.GetRowCellValue(i,"MESSAGE").ToString();
                string ttd = lblTandaTangan.Text;
                string msg = pesan + Environment.NewLine + Environment.NewLine + ttd;  //SENT MESSAGE USING SIGNATURE
    
            var listPhoneNumber = new List<string>();
            listPhoneNumber.Add(gridView1.GetRowCellValue(i, "PHONENUMBER").ToString());
    
            foreach (var phoneNumber in listPhoneNumber)
            {
                var pdu = new SmsSubmitPdu(msg, phoneNumber, string.Empty);
                CommSetting.comm.SendMessage(pdu);
    
                //---------------STORE TO ORACLE DB--------------------
                if (koneksi_manual.con.State == ConnectionState.Open)
                {
                    koneksi_manual.con.Close();
                }
                koneksi_manual.con.Open();
    
                OracleCommand cmd = new OracleCommand();
                cmd.CommandText = @"INSERT INTO MESSAGESENT (ID, DATE, TIME, PHONENUMBER, MESSAGE) VALUES 
                                (SQ_MESSAGESENT.NEXTVAL, '" + DateTime.Now + "', TO_DATE('" + DateTime.Now + "', 'dd/MM/yyyy hh24:mi:ss'), '"
                                    + gridView1.GetRowCellValue(i, "PHONENUMBER") + "', '" + pesan.Replace("'", "''") + "', '" + Program.IDUser + "')";// <= Use gridView1.GetRowCellValue to get the cell value.
                cmd.Connection = koneksi_manual.con;
                cmd.ExecuteNonQuery();
    
                //Sleeps system for 1000ms for refreshing GSM Modem
                System.Threading.Thread.Sleep(1000);
    
                //DELETE MESSAGE SENT FROM OUTBOX
                var obj = gridView1.GetRowCellValue(i, "ID");
    
                OracleCommand cmd2 = new OracleCommand();
                cmd2.CommandText = "DELETE FROM OUTBOX WHERE ID = '" + obj + "'";
                cmd2.Connection = koneksi_manual.con;
                cmd2.ExecuteNonQuery();
            }
            MessageBox.Show("Message Sent", "Notif");
          }
        }