Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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 8-Oct-12 4:43am
Comments
Ashraff Ali Wahab at 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?
BasicsLearner at 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 at 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.
BasicsLearner at 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 at 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.
BasicsLearner at 12-Oct-12 3:28am
   
Hi Ashraff,
Yes I am getting alert box message three times if keep message box inside foreach loop. and as you saying if there is any problem with my sms code it should NOT send three SMS messages while I am running application in debug mode by keeping a break point. it is sending messages if I running in DEBUG mode. if I run normally it is sending only one message.

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

  Print Answers RSS
0 OriginalGriff 405
1 Sergey Alexandrovich Kryukov 220
2 Maciej Los 195
3 Peter Leow 190
4 DamithSL 174


Advertise | Privacy | Mobile
Web01 | 2.8.140705.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid