Logic says: User 1 sends a message to User 2 via Server 1. Server 1 records it in DB (mysql) and sends the message to Server 2 to be sent to User 2. Server 1 responds to User 1 that message has been sent. While at the back-end (asynchonously) Server 1 keeps requesting Server 2 for the delivery of the message, when delivered, updates the database and set delivery status as delivered or failed (after few hours of re-trying).
But I don't think this code is working. Because database never gets updated.
SendMessage.aspx
- protected void btnSend_Click(object sender, EventArgs e)
- {
- global g = new global();
- g.CallUpdateSMSStatus(cmdSMS.LastInsertedId.ToString(), msgID);
- }
global.cs
- public async void CallUpdateSMSStatus(string strMsgID, string strMsgID)
- {
- await updateMessageStatus(strMsgID, strMsgIDServer);
- }
-
- public async Task updateMessageStatus(string strMsgID, string strMsgID)
- {
- global g = new global();
- int timer = 10000;
- int intStatus = 2;
-
- while (intStatus == 2)
- {
- await Task.Run(() =>
- {
- intStatus = g.checkSMSStatus(strMsgIDServer);
-
- if (intStatus != 2)
- {
-
- }
- else
- {
- if (timer < 3600000)
- {
- timer *= 10;
- }
- Thread.Sleep(timer);
-
- }
- });
- }
- }