Click here to Skip to main content
15,886,019 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am working on wpf application.it sends SMS using in background.
every thing is working as I expected. But I want to send SMS to multiple numbers.
here is my code..
namespace CSMsystem
{
    
    public partial class adminwelcome : Page
    {
        private string[] ports;
        ...............
        ...............
        ..............
        private readonly BackgroundWorker worker = new BackgroundWorker();
        public adminwelcome()
        {
            InitializeComponent();
            loaduserbut();
            worker.DoWork += sendingSMS;
            worker.RunWorkerCompleted += smsCompleted;

        }
 

        public void loaduserbut()
        {
            loadPorts();
            ..........
            ..........
            ..............
            if (status == "thankYou")
            {
                
                worker.RunWorkerAsync();
                ...........
                ...........
                ...........
            }
            else if (status == "comments")
            {
               ..............
               ...............
               ............ 
            }
            else if (status == "final")
            {
                .....................
                ................
            }
            
        }
        ...................
        ......................
        ......................
        ....................
        //Loading ports
        private void loadPorts()
        {
            ports = new string[3];
            ports = SerialPort.GetPortNames();
        }
        //sendSMS
        private void sendingSMS(object sender, DoWorkEventArgs e)
        {
            SmsClass sm = new SmsClass(ports[0]);
            try
            {
                foreach (MobileDtl_Base mobBase in adminwelcome.mobilNumList)
                {
                    sm.Opens();
                    //sendSMS(mobBase.MobileNo.ToString());
                    sm.sendSms("0" + mobBase.MobileNo.ToString(), "There is a feedback from a customer :" + custName + ", R.O.NUM :" + roNum);
                    sm.Closes();
                   System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //
        private void smsCompleted(object sender,
                                       RunWorkerCompletedEventArgs e)
        {
            MessageBox.Show("Messages are sent !!");
        }

    }
}


It is sending multiple SMS if Debug. but while running application it is sending SMS for first contact.
Please help on this issue
Posted
Comments
Ashraff Ali Wahab 8-Oct-12 11:24am    
1.Are you getting any exception
2.You see the message "Messages are sent !!"
3.You see the exception in Message Box
4.Did you checked the size of adminwelcome.mobilNumList.Is it 1?
Basics Learner 9-Oct-12 10:51am    
Hello Ashraff,
Thanks for your time.
1.No I am not getting any exception and exception in message box.
2.Yes I am seeing Message box saying "Messages are sent !!"
3.No
4. Yes I checked it there is 3 numbers in List.
* here have to notice one thing. if I debug and go through step by step it is sending messages to all numbers. with out no issue.
If I run application it is sending only one message to first number in List. seems some thing strange

Best regards,
Shree
Ashraff Ali Wahab 9-Oct-12 14:00pm    
Can you remove the System.Threading.Thread.Sleep(1000); and try.It is a hunch.I'll try it and let you know.
Basics Learner 10-Oct-12 0:39am    
Hi Ashraff,
it not a matter not working at all.
I used sleep to keep a gap . but it is not working

Thanks

Shree

Ashraff Ali Wahab 10-Oct-12 11:50am    
Then it should be a prblem with your sm.sendSms method.Just remove the sms code in for loop show the message box to display mobBase.MobileNo.ToString() to narrow down the issue.If it is showing message three times then it is the problem with your SMS code and if it doesnt then it is the problem with your BackgroundWorker code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900