Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:28:57+00:00 2026-06-09T17:28:57+00:00

I can send a message from my application by writing port.WriteLine(AT+CMGS=\ + m.Groups[2].Value +

  • 0

I can send a message from my application by writing

port.WriteLine("AT+CMGS=\"" + m.Groups[2].Value + "\"");
port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26));

This is fine. But now I want to send bulk messages to a group of numbers. I have this loop to send messages to a group of numbers:

foreach (ListViewItem item in bufferedListView1.Items)
{
    string lname = bufferedListView1.Items[i].Text;
    string lno = bufferedListView1.Items[i].SubItems[1].Text;
    string gname = bufferedListView1.Items[i].SubItems[2].Text;
    string line = lname + "@" + lno + "@" + gname;
    if (gname.Contains(sgroup))
    {
        var m = Regex.Match(line, @"([\w]+)@([+\d]+)@([\w]+)");
        if (m.Success)
        {
            port.WriteLine("AT+CMGS=\"" + m.Groups[2].Value + "\"");
            port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26));
            Thread.Sleep(4000);
        }
        sno++;
    }
    i++;
}

This works well too. But the issue is with the UI, becoming irresponsive for quite a good amount of time. Any better ways to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:28:59+00:00Added an answer on June 9, 2026 at 5:28 pm

    Use a BackgroundWorker – they are really easy to use and manage the threading in an encapsulated manner. The benefit of this class is that it supports cancellation if you want to be able to cancel the process and it supports reporting progress, both of which I’ll show here. Finally, the nice thing about this class is that when it reports progress it switches threads properly, ensuring you aren’t writing to the UX on a separate thread – but the code inside the DoWork event handler is still managed correctly on a separate thread.

    You would do something like the following.

    // in this example this is scoped to the class, but just scope it appropriately
    private BackgroundWorker worker = new BackgroundWorker();
    
    ......
    
    // because I don't really know anything about how your program is structured I'm not sure
    // where you want to place all of the definitions OR where you want to place RunWorkerAsync
    // but you want the definitions to happen ONCE and the RunWorkerAsync to be where the USER
    // initiates it
    
    // this will allow you to consume the ProgressChanged event
    worker.WorkerReportsProgress = true;
    
    // this will allow you to set the CancellationPending property
    worker.WorkerSupportsCancellation = true;
    
    worker.DoWork += (o, args) =>
    {
        foreach (ListViewItem item in bufferedListView1.Items) 
        { 
            string lname = bufferedListView1.Items[i].Text; 
            string lno = bufferedListView1.Items[i].SubItems[1].Text; 
            string gname = bufferedListView1.Items[i].SubItems[2].Text; 
            string line = lname + "@" + lno + "@" + gname; 
            if (gname.Contains(sgroup)) 
            { 
                var m = Regex.Match(line, @"([\w]+)@([+\d]+)@([\w]+)"); 
                if (m.Success) 
                { 
                    port.WriteLine("AT+CMGS=\"" + m.Groups[2].Value + "\""); 
                    port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26)); 
                    Thread.Sleep(4000); 
                } 
                sno++; 
            } 
            i++; 
        }
    }
    
    worker.ProgressChanged += (s, args) =>
    {
        // set some progress here, the ProgressChangedEventArgs inherently supports an integer
        // progress via the ProgressPercentage property
    }
    
    worker.RunWorkerCompleted += (s, args) =>
    {
        // with the RunWorkerCompletedEventArgs class you can check for errors via Error, did
        // cancellation occur via Cancelled, and you can even send a complex result via the Result
        // property - whatever you need
    }
    
    // this starts the work in the DoWork event handler
    worker.RunWorkerAsync();
    

    Here is a link to Microsoft’s documentation on this matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to send a message from a WPF application's textbox to an
I am attempting to create a simple app that can send a text message
I want to send a window message from one application (console) to the wondow
i am writing an application using mongodb in which user can send messages to
I'd like to use JMeter test that I can send a message to a
I've successfully sent message to individual user. How can I send message to a
Is the communication bi-directional in NServiceBus ? a subscriber can also publish/send message?
when I send message as client using quickfix, how can I know if it's
I want to create a PHP app that can send text messages ; There
i have an iphone 3g and can successfully send text messages using the PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.