• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

How do i reduce the 'lag' on my application?

Hi,

atm, im writing an application using VB. What it does is actually, reading sms frm the GSM modem into my databse, and it will send the sms out again at the time which is stated in the sms ealier on.

so now i have encounted a problem whereby some of the SMS, which is saved into my databse, are unable to send out zome of the SMSes.
EG.
1:55:00 PM          a
1:55:01 PM          b
1:55:02 PM          c
1:55:03 PM          d
1:55:04 PM          e
1:55:05 PM          f
1:55:06 PM          g
1:55:07 PM          h
1:55:08 PM          i
1:55:09 PM          j
1:55:10 PM          k
1:55:11 PM          l
1:55:12 PM          m
1:55:13 PM          n
1:55:14 PM          q

only a, f, j, n are recieved on my phone. the rest of it wld be skipped.
sometimes, of say if i were to run this program for 3 hrs.. in between minutes like. 3:02 PM, 3:03 PM, 3:04 PM.

only 3:02 and 3:04 PM would be sent.

my timer1 is 1000.

so is there anyway to eliminate such problems?
0
dpapkin
Asked:
dpapkin
  • 4
  • 4
  • 3
  • +2
3 Solutions
 
kaylanreilorCommented:
It depends on the way you are sending them. Maybe you cannot reduce the time needed to send an SMS and when you try to send one during a previous one is already processed, your operation simply failed and you didn't treated the error. Probably you decoupled the operation to send an SMS by using another thread. You should have a queue with all the message that are to be sent and them a thread which is reading sequencially the queue before sending them. And when you call "send" your thread should block until the end before dequeuing the next message.
0
 
Shanmuga SundaramCommented:
Since you mentioned that your timer interval is set to 1000 then it is correct and your program should trigger sending sms for every second. But from your comment it is known that due to some reasons the timer is not able to execute every 1 second. So better try reducing the timer interval to less than 1000 and check whether it helps.
0
 
dpapkinAuthor Commented:
hmm ok i have tried putting the timer @ 500...

though the program is running, but the application window is not responsive !
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
EDDYKTCommented:
even you change the timer to 500 ms and you want to sent the SMS every second, you need to keep track the time you have sent.

ie
Option Explicit

Private t1 As Date

Private Sub Form_Load()
Timer1.Interval = 500
Timer1.Enabled = True
t1 = Now
End Sub

Private Sub Timer1_Timer()
If (DateDiff("s", t1, Now) > 0) Then
    t1 = Now
    ' send you SMS message
End If
End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can we see your looping logic and timer code?
0
 
dpapkinAuthor Commented:
i hope this part of the code helps.
private void timer1_Tick(object sender, EventArgs e)
        {
            
            string storage = GetMessageStorage();
            label1.Text = DateTime.Today.DayOfWeek.ToString();
            label2.Text = DateTime.Now.ToString();
            SmsSubmitPdu pdu;

            mycon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\My Dropbox\FYP docs\website program\database\trialdata.mdb;Persist Security Info=False");

            OleDbCommand obj1 = new OleDbCommand("SELECT Student_Phone_Number, Text_Message , Reporting_Time ,Reporting_Day FROM studentremainder ", mycon);
            mycon.Open();

            OleDbDataReader aReader = obj1.ExecuteReader();

            string realtime = DateTime.Now.ToString();
            char[] delimiters = new char[] { '*' };
            string numbe;
            string number;
            string number0;
            string number1;
            string number2;
            OleDbCommand myCommand = new OleDbCommand();
           myCommand.Connection = mycon;
           // myCommand.CommandText = "INSERT INTO Query1( [Student_ID_adm], [Text_Message], [Reporting_Day], [Reporting_Time]) VALUES (@Student_Phone_number, @Student ID adm, @Text_Message, @Reporting_Day, @Reporting_Time)";
            //myCommand.CommandText = "INSERT INTO Query1([Text_Message], [Reporting_Day], [Reporting_Time])VALUES (@Text_Message, @day, @time)";
           myCommand.CommandText = "INSERT INTO Query1([Student_Phone_number],[Student_ID_adm],[Reporting_Day],[Reporting_Time],[Text_Message]) VALUES (ha,he,hou,hi,ju)";
           
            try
            {
                // Read all SMS messages from the storage
                
                storage = PhoneStorageType.Phone;
                DecodedShortMessage[] messages = comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, storage);
                foreach (DecodedShortMessage message in messages)
                {
                    Output(string.Format("Message status = {0}, Location = {1}/{2}",
                        StatusToString(message.Status), message.Storage, message.Index));
                    ShowMessage(message.Data);
                    string h = message.Data.UserDataText.ToString();
                    Output(h);
                    Output("");
                    //
                    /*
                     if (h == "help")
                     {
                       pdu = new SmsSubmitPdu(message.data.orginatingaddress,"the format is....", "");
                     }
                     */
                    if ((h == "help") || (h == "Help"))
                    {
                        pdu = new SmsSubmitPdu("the format is <PhoneNo>*<AdminID>*<DD/MM/YYYY>*<H:MM:SS AM/PM>*<YourTextMessage>", num, "");
                        comm.SendMessage(pdu);
                    }

                    string[] parts = h.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                    
                    for (int i = 0; i < parts.Length; i++)
                    {
                        //Output(parts[i]);
                        if (i == 0)
                        {
                            numbe = parts[0];
                         //   Output(numbe);

                            myCommand.Parameters.Add("ha", OleDbType.VarChar).Value = numbe.ToString();
                        }
                        if (i == 1)
                        {
                            number=parts[1];
                          //  Output(number);
                            
                           myCommand.Parameters.Add("he", OleDbType.VarChar).Value = number.ToString();
                           // myCommand.ExecuteNonQuery();
                        }
                        if (i == 2)
                        {
                            number0 = parts[2];
                        //    Output(number0);
                           // myCommand.CommandText = "INSERT INTO Query1([Text_Message]) VALUES (hou)";
                            myCommand.Parameters.Add("hou", OleDbType.VarWChar,10).Value = number0.ToString();
                           // myCommand.ExecuteNonQuery();
                        }
                        if (i == 3)
                        {
                            number1 = parts[3];
                          //  Output(number1);
                         //   myCommand.CommandText = "INSERT INTO Query1([Reporting_day]) VALUES (hi)";
                         myCommand.Parameters.Add("hi", OleDbType.VarWChar).Value = number1.ToString();
                        // myCommand.ExecuteNonQuery();
                        }
                        if (i == 4)
                        {
                            number2 = parts[4];
                        //    Output(number2);
                          myCommand.Parameters.Add("ju", OleDbType.VarWChar).Value = number2.ToString();
                          //myCommand.ExecuteNonQuery();
                          pdu = new SmsSubmitPdu("You have successfully registered ! ", num, "");
                          comm.SendMessage(pdu);
                        }
                   
                    }
                    
                    //myCommand.CommandText = "INSERT INTO Query1([Text_Message],[Reporting_Time]) VALUES ('number','number1')";// only allow string number and number2
                    myCommand.ExecuteNonQuery();
                }
               // Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
                //Output("");
                
                while (aReader.Read())
                {
                    // Console.Write(aReader.GetString(2).ToString() + " ,");
                    // Console.Write(aReader.GetString(3).ToString() + " ,");
                    string c = aReader["Reporting_Time"].ToString();
                    string d = aReader["Reporting_Day"].ToString();
                    //label19.Text = c;
                    //label21.Text = d;
                    string g = d + " " + c;
                    //label5.Text = g;
                    if (g == realtime)
                    {
                        Console.Write(aReader.GetInt32(0).ToString() + " ,");//string(0) refer to phone
                        Console.Write(aReader.GetString(1).ToString() + " ,");//string(1) refer to message

                        string a = aReader["Text_Message"].ToString();
                        string b = aReader["Student_Phone_number"].ToString();
                        pdu = new SmsSubmitPdu(a, b, ""); // use for senting message
                        comm.SendMessage(pdu);
                    }
                }
                aReader.Close();
                mycon.Close();
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
            finally
            {

            }

            //  Cursor.Current = Cursors.Default;
        }

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try turning off the Timer, executing your code, then turning the Timer back on:
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            
            // ...all of your existing code here...

            timer1.Start();
        }

Open in new window

0
 
dpapkinAuthor Commented:
i dont quite understand you idle mind..

are u suggesting tat i...

1. add the timer1.start/stop into the codes
2. build the solution
3. delete away timer1.start/stop
4. build the solution again
5. run my program

yes?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
No sir...you LEAVE the Start/Stop in the code.

When the Timer1 fires, you stop it via code in the Tick() event, execute your SMS code, then turn it back on at the end of the event.  This should prevent it from "stacking" on top of itself...
0
 
dpapkinAuthor Commented:
ok its great tat my application window is responding perfectly... well abt 0.5s delay but still ok..

but when i look @ the time (the time is compared to my computer time) on my application.. it sometimes it jumps 2 seconds or 3 seconds.

is it normal? or this problem can be solved?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I think you need to look at how long it takes to actually send the SMS messages.  If it takes much less than one second then you can calculate how much time until the next "top of the second" and adjust the Interval so it fires again when you want.
0
 
kaylanreilorCommented:
dpapkin,
After all this messages you go back to what I told you in the first comment of this thread : you are probably trying to send a 2nd SMS while the first one is not finished to be sent. So you should block this "send" operation before trying to send another one. And also reading the DB in your timer1_Tick event handler could be an issue as well. As I suggest several days ago now, you should have a cache in the memory of your program which is filled up in another thread and which is working as a queue. The event handler which is sending the SMS should dequeue these message in a blocking and thread safe manner.
Long story short, refactor your architecture here instead of trying to make working something which is awkward. If you continu this way, you will probably find a workaround to make it more or less working... until the next bug.
0
 
kaylanreilorCommented:
So for the third time I say it:
sending the SMS should be blocking for a separate thread which role would ONLY be to send the message. Another thread would be used to populate a queue with the messages that need to be sent and that are read from the DB that the "send" thread would dequeue. There is no other way to do it since the real issue here is that reading the data from the DB is faster then sending the data through some SMSs.
See my 2 previous comments in which I already explain this !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now