1
我有这个if条件,如何在c#中延迟执行方法?
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
}
和我sendSMS方法是这样的,
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;
}
会发生什么事,当我在使用断点是我sendSMS
让我的输出(即)两个方法得到执行和消息正确发送......但是当我删除了我的断点时,if
语句中的方法都被执行,但来自第一个方法的消息被发送,而不是来自第二个方法....任何建议?
不能得到你的观点..请多解释一下.. – 2010-06-14 13:58:52
@Pandiya,我详细阐述了我的答案。如果您仍然有疑问,请告诉我。 – 2010-06-14 17:39:34
你可以发布重构方法使用相同的端口的示例代码.... – 2010-06-15 04:16:45