问题描述:

I want to create a C# application that will automatically detect incoming SMS. It will process the message in that SMS and resend something to that same number the SMS came from. I can successfully send and receive SMS but cannot make program to automatically detect SMS and process it. The code I developed works only for few SMS then it stops working. What is wrong in this code and if there is another better way to do this?

in this code I 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());

}

}

相关阅读:
Top