How to delay execution of a method in c#?

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-06-14T13:49:20Z Indexed on 2010/06/14 13:52 UTC
Read the original article Hit count: 148

Filed under:
|
|

I have this if condition,

if (sendSMS(Convert.ToInt32(DLComportNo.SelectedItem.Text), TxtDriMob.Text,
TxtCliDet.Text) && sendSMS(Convert.ToInt32(DLComportNo.SelectedItem.Text), 
TxtCliMob.Text, TxtDriDet.Text))
{
     // I am inserting details to my db
}

and my sendSMS method looks like this,

private bool sendSMS(int portNo, string mobNo, string details)
{
    try
    {
        SerialPort SerialPort1 = new SerialPort();
        SerialPort1.PortName = "COM" + portNo.ToString();
        SerialPort1.BaudRate = 9600;
        SerialPort1.Parity = Parity.None;
        SerialPort1.DataBits = 8;
        SerialPort1.StopBits = StopBits.One;
        SerialPort1.RtsEnable = true;
        SerialPort1.DtrEnable = true;
        SerialPort1.Encoding.GetEncoder();
        SerialPort1.ReceivedBytesThreshold = 1;
        SerialPort1.NewLine = Environment.NewLine;
        SerialPort1.Open();

        SerialPort1.Write("AT" + SerialPort1.NewLine);
        Sleep(500);
        SerialPort1.Write("AT+CMGF=1" + SerialPort1.NewLine);
        Sleep(500);

        SerialPort1.Write("AT+CMGS=" + (char)34 + mobNo + (char)34 +
                               SerialPort1.NewLine); 
        Sleep(1000);
        SerialPort1.Write(details + (char)26);
        Sleep(2000);

        SerialPort1.Close();

    }
    catch
    {

    }
    return true;
}

What happens is when i use break point in my sendSMS i get my output (ie) both the methods get executed and messages are sent properly... But when i removed my breakpoint both the methods in the if statement are executed but message from the first method is sent and not from the second method.... Any suggestion?

© Stack Overflow or respective owner

Related posts about c#

Related posts about conditional