Sending SMS at the same time

I posted a question earlier about multithreading. Actually my intention is to send SMS to 1000 (or more) people at the same point in time (example: 12:00 AM sharp) using C # and asp.net apps. Is there a choice of multithreading concept to achieve this goal?

+2


source to share


5 answers


This concept is not needed Multi Threading ...

This concept is more of a Task Manager / Cron Job

  • Create an ASPX Script that sees the time and executes the method you need.
  • Configure Task Manager to run this Script every xx minutes
  • Create a method that picks a list of people and sends SMS via SMS API and calls it eg. SendSMSFromList (User ListList, string message) {}
  • Now set everything up and you run it anytime (just set it to ASPX Script)

Please feel free to tell me if you need some code for this.


edited for all steps


If you have a hosting solution, in your hosting control panel, you have something like Task Schedule that you can configure to run the Script page every n minutes, if so please take the following steps. If, on the other hand, you are running your own server (IIS), then do that first.



  • Install cUrl for windows from this location and add curl.exe to C: \ WINDOWS
  • Open Task Manager (Control Panel> Administrative Tools> Task Scheduler on win7)
  • Create a new task like this
  • Run the command

curl http: //localhost/yourApp/taskManager.aspx

with this, you just configured your system to run the file, as if you followed this link in your browser, which will run every 15 minutes.

Now we need to create taskManager.aspx file

public partial class taskManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Now;

        // Run after midnight
        if (dt.Hour == 0 && dt.Minute <= 15)
        {
            Write2Log("Schedule Job Started", LogType.INFO);

            SendSMSFromList(
                GetUsersList(), 
                GetSMSMessage());

            Write2Log("Schedule Job Finished", LogType.INFO);
        }
    }

    private string GetSMSMessage()
    { 
        // Fetch the text from DB...

        return "This is the message content that I will send as SMS"; 
    }

    private List<string> GetUsersList()
    { 
        // fetch the list form DB...

        return new List<string>(); 
    }

    private void SendSMSFromList(List<string> usersList, string message)
    { 
        // send SMS's
        foreach (string phoneNr in usersList)
        { 
            // send message
            mySMSAPI.Send(phoneNr, message);
        }
    }

    private void Write2Log(string text, LogType type)
    { 
        // Log to a file what going on...
        try
        {
            string filename = HttpContext.Current.Server.MapPath("") + "\\status.log";
            using (StreamWriter sw = new StreamWriter(filename, true))  // open to append
            {
                // example: 2008-12-17 13:53:10,462 INFO - Schedule Job Finished
                string write = String.Format("{0} {1} - {2}",
                                DateTime.Now,
                                type.ToString(),
                                text);

                sw.WriteLine(write);
            }
        }
        catch (Exception)
        { }
    }

    private enum LogType
    { INFO, WARNING, ERROR }
}

      

Done ...

I did everything in one file for the sake of example, you should split things ... but what I wanted was to show you the principle of this.

+6


source


Depending on how the SMS is sent. If you are allowed to tell a web service that is sending SMS, you will receive a request 1000 times in one moment, which will not solve your problem.

To do this, you need to make sure that the submit task can be done at the same time.

EDIT:
Also, I agree that the number of threads will not be healthy for your system.



Edit2: How necessary is it? Assuming hh: mm is enough, you need to send 60 seconds about 1000 cm. This means you need to send aprox 17 SMS per second. If you share this allows you to say 4 streams, then you will only need to make sure your sending process / device can send 4 SMS / s. it should be achievable I think.

NTN

+2


source


I don't know how you text them. But almost all major sms service providers will let you send 1000 within 1 second.
So if you REALLY REALLY REALLY REALLY REALLY need to send them all at once, I suggest you just loop through and send the information to the service provider one at a time.

+2


source


I don't think this will work for you and creating that many threads is not recommended.

Also see link

maximum-number-of-threads-in-a-net-app

Is the SMS app allowed to send by mail? Or maybe use different services in different mailboxes to send these subsets of sms. But I think it will be difficult to send such a volume right away.

+1


source


I suspect you will have some transportation problems getting so much data to your SMS provider at that moment, assuming this is a real time process.

I will find a provider that can handle the scheduled messages and then post messages to the queue to be sent at 12am at my leisure.

0


source







All Articles