mCore™ .NET SMS Library 1.2

Queue.Clear Method

Description:

The Clear property removes all unsent messages from the message queue (instance of mCore.Queue class returned by mCore.SMS.Queue method). It does not clear the message from the queue if it is currently in the process of being sent.


Namespace: mCore
Assembly: mCoreLib (in mCoreLib.dll)

Exceptions:

mCore.GeneralException

Usage Example:

Visual Basic
Public Class MyClass
   Public WithEvents objSMS As New mCore.SMS
   Public Sub SendQueue()
      Dim strResult As String = ""
      Dim strMsg As String = "This is a test message"
      Dim strKey as String
      Try
         SetCommParameters()
         objSMS.Encoding = mCore.Encoding.GSM_Default_7Bit
         objSMS.LongMessage = mCore.LongMessage.Concatenate
         objSMS.DeliveryReport = True

         strKey = objSMS.SendSMSToQueue("+919873094767", strMsg, _
                     mCore.QueuePriority.High)
         MsgBox("Message added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         objSMS.DeliveryReport = False
         'No delivery report for the following message
         strKey = objSMS.SendSMSToQueue("+919810098765", strMsg)
         MsgBox("Message added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         objSMS.DeliveryReport = True
         strKey = objSMS.SendSMSToQueue("+919811045678", strMsg, _
                     mCore.QueuePriority.Low)
         MsgBox("Message added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         strKey = objSMS.SendSMSToQueue("+919873012345", strMsg, _
                     mCore.QueuePriority.High)
         MsgBox("Message added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         MsgBox("Total messages in queue: " & objSMS.Queue.Count.ToString)

         objSMS.Queue.Clear()

         'After clear method is called the queue will be empty
         MsgBox("Total messages in queue: " & objSMS.Queue.Count.ToString)

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
      Catch ex As Exception
      End Try
   End Sub

   Public Sub SetCommParameters()
      Try
         objSMS.Port = "COM1"
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200
         objSMS.DataBits = mCore.DataBits.Eight
         objSMS.StopBits = mCore.StopBits.One
         objSMS.Parity = mCore.Parity.None
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message)
      Catch ex As Exception
      End Try
   End Function
End Class
 
C#

class MyClass
{
   public mCore.SMS objSMS = new mCore.SMS();

   public static void SendQueue()
   {
      string strResult = "";
      string strMsg = "This is a test message";
      string strKey = "";
      try
      {

         SetCommParameters();
         objSMS.Encoding = mCore.Encoding.GSM_Default_7Bit;
         objSMS.LongMessage = mCore.LongMessage.Concatenate;
         objSMS.DeliveryReport = true;

         strKey = objSMS.SendSMSToQueue
                        ("+919873094767", strMsg, mCore.QueuePriority.High);
         MessageBox.Show("Message added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         objSMS.DeliveryReport = false;
         //No delivery report for the following message
         strKey = objSMS.SendSMSToQueue
                        ("+919810098765", strMsg, mCore.QueuePriority.Low);
         MessageBox.Show("Message added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         objSMS.DeliveryReport = true;
         strKey = objSMS.SendSMSToQueue
                        ("+919811045678", strMsg, mCore.QueuePriority.High);
         MessageBox.Show("Message added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         //Message queue is enabled
         objSMS.Queue.Enabled = true;

         //Messages can be added to the queue even
         //when the Message queue is enabled

         strKey = objSMS.SendSMSToQueue
                        ("+919873012345", strMsg, mCore.QueuePriority.High);
         MessageBox.Show("Message added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");
         MessageBox.Show("Total messages in queue: " +
                  objSMS.Queue.Count.ToString());

         objSMS.Queue.Clear();

         //After clear method is called the queue will be empty
         MessageBox.Show("Total messages in queue: " +
                  objSMS.Queue.Count.ToString);
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }

   public static void SetCommParameters()
   {
      try
      {
         objSMS.Port = "COM1";
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200;
         objSMS.DataBits = mCore.DataBits.Eight;
         objSMS.StopBits = mCore.StopBits.One;
         objSMS.Parity = mCore.Parity.None;
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS;
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }
}

See Also:

mCore.SMS.Queue Method
Queue.Enabled Property
Queue.Count Property

 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved