This project is read-only.

Receiving SMS messages with multiple threads

Aug 10, 2012 at 4:08 PM


I have been using the lib for receiving SMS only. I handle the received text with the event handler as suggested in the How To.

But on the "Multi-Threading Issues" How to it says that the programmer must " ensure that all SmppClient event handlers, and other methods accessible from the event handlers are thread-safe"

Does this mean that in the event-handler one has to add some sort of lock when reading the value of the"MessageEventArgs e", something like this:

        public static void client_MessageReceived(object sender, MessageEventArgs e)



           //The event argument e contains more information about the received message
            TextMessage textMsg = e.ShortMessage as TextMessage; //This is the received text message
            Console.WriteLine("AddressTon: {0}, SourceAddress: {1}, AddressNpi: {2}", c.Properties.AddressTon.ToString(), c.Properties.SourceAddress, c.Properties.AddressNpi.ToString());
            string msgInfo = string.Format("Sender: {0}, Receiver: {1}, Message content: {2}", textMsg.SourceAddress, textMsg.DestinationAddress, textMsg.Text);
            //Display message



can somebody post an example on how to make this receiving process thread safe?

thank you, great library btw


Aug 17, 2012 at 7:02 PM
The "MessageReceived" event handler is called by a random thread from the thread pool and it is possible that it can be called simultaneously by more than one thread.

The code snipped you provided is thread safe, and thus should be able to do it.
Aug 17, 2012 at 7:21 PM

Thank you,