我想创建一个自动检测传入短信的C#应用程序。它将处理该SMS中的消息并将某些内容重新发送到SMS来自的相同号码。我可以成功发送和接收短信,但不能让程序自动检测短信并处理它。我开发的代码仅适用于少量短信,然后停止工作。这段代码有什么问题,还有另外一种更好的方法吗?
在此代码中我{cal runTimer()
..
public void RunEvent(object source, ElapsedEventArgs e)
{
try
{
int uCountSMS = objclsSMS.CountSMSmessages(port);
if (uCountSMS > 0)
{
objShortMessageCollection = objclsSMS.ReadSMS(this.port, strCommand);
foreach (ShortMessage msg in objShortMessageCollection)
{
if (msg.Sender == "+923007302422")
{
// this.textBox1.Text = "no";
if (msg.Message == "code")
{
objclsSMS.sendMsg(this.port, "any number", "good");
}
else if (msg.Message == "hi")
{
objclsSMS.sendMsg(this.port, "anynumber", "bye");
}
// objclsSMS.DeleteMsg(this.port, "AT+CMGD=1,3");
}
}
}
}
catch (Exception ex)
{
ErrorLog(ex.ToString());
}
}
public void runTimer()
{
try
{
System.Timers.Timer aTimer = new System.Timers.Timer(3000);
aTimer.Elapsed += new ElapsedEventHandler(RunEvent);
// aTimer.Interval = 3000;
aTimer.Enabled = true;
}
catch (Exception ex)
{
ErrorLog(ex.ToString());
}
}