What is the best way to call Long-Running Task?

Hi Experts,

I have the following environment:

- Visual Studio 2005
- .NET Framework 2.0
- Windows Server 2003

I am creating a web application, which have the following functions...

- Single START button to start the EE process
- EE Process is still running even though web browser is closed
- EE Process will retrieve Client record from our database and call Vendor provided API to send SMS.
- Approximately 100,000 mobile numbers need to send each day
- Each API call take about 5 seconds

What do you recommend for completing this application?
What is the common technique required to running the long running task?
bbkevinAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
OK.
Split the mobile numbers in batches of say 5000 (eg. store in a List<String>) and pass each collection onto a new thread.  The thread processes each collection as you currently do.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>Approximately 100,000 mobile numbers need to send each day
>>Each API call take about 5 seconds

By my reckoning that is over 13 days of work being done per day !!  

Can you send multiple SMS's simultaneously? - ie. 20 threads, each processing its own set of 5000 numbers and so you might have 20 SMS's being sent at one instant.
0
 
käµfm³d 👽Commented:
EE Process is still running even though web browser is closed
Which means the task is running on the server. I would suggest forking this off to another process. I wouldn't think you'd want your web server application doing all that work.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
bbkevinAuthor Commented:
Hi AndyAinscow,

Yes. It has so many SMS to send. The API may failed, so I have to get the result back for each call.

Hi Kaufmed,
Transfer the function to Service?

I attached my current applications for yours to review...
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Please click on the 'START' button to begin.<br />
        <br />
        <asp:Button ID="btnStart" runat="server" Text="START" OnClick="btnStart_Click" />
    </div>
    </form>
</body>
</html>

Open in new window

Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnStart_Click(object sender, EventArgs e)
    {
        string connectionString = "Data Source=localhost;Initial Catalog=SMS;Integrated Security=SSPI;";
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandText = "SELECT ClientName, MobileNumber FROM SMSList";
            conn.Open();
            SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                EESMSAPI objEE = new EESMSAPI();
                bool result = objEE.SendSMS(reader["ClientName"].ToString(), reader["MobileNumber"].ToString());

                using (SqlConnection conn2 = new SqlConnection(connectionString))
                {
                    SqlCommand comm2 = new SqlCommand();
                    comm2.Connection = conn2;
                    comm2.CommandText = "Update SMSList SET Result = @Result, SendDate = GETDATE() WHERE MobileNumber = @MobileNumber";
                    conn2.Open();
                    comm2.Parameters.AddWithValue("@Result", result);
                    comm2.Parameters.AddWithValue("@MobileNumber", reader["MobileNumber"].ToString());
                    comm2.ExecuteNonQuery();
                }
            }
            reader.Close();
        }
    }
}

Open in new window

SMSResult.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SMSResult.aspx.cs" Inherits="SMSResult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Open in new window

SMSResult.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class SMSResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string connectionString = "Data Source=localhost;Initial Catalog=SMS;Integrated Security=SSPI;";
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandText = "SELECT ClientName, MobileNumber, Result FROM SMSList WHERE SendDate >= CAST(convert(varchar, getdate(), 111) AS DATETIME) ORDER BY ClientName ASC";
            conn.Open();
            GridView1.DataSource = comm.ExecuteReader(CommandBehavior.CloseConnection);
            GridView1.DataBind();
        }
    }
}

Open in new window




0
 
Rose BabuSenior Team ManagerCommented:
Hi,

if the problem is the longtime running process then you may consider the below points.


in your case, why dont you create a window application and do your code in that.?
and make the application to be scheduled in win 2003 server (Task Scheduler) at a specific time.

this process will be automated in your server and will be finished at the background.

also in your application, have a log to be created for your reference.
and code an email function to your email id for the details (SMSResult.aspx details for your info)

Hope you may get an idea.

Happy programming.
0
 
bbkevinAuthor Commented:
Hi AndyAinscow,
Browser will timeout...

Hi Srosebabu,
The website is used by clients in remote location, clients just want to do all the operations within their favorite Internet Explorer.
The application cannot be scheduled, because they may not send SMS on weekend, public holiday or peak period. (This is totally depend on client preference.)

This is very similar to Bulk SMS service. Client login to the website, click START, Logout, and then close the browser.
Few hours later, they logon to the website again, and check the Status.


I heard someone using Async Web Service, do you recommend?
or have any other ideas?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>>Browser will timeout...

and what does that mean?  From what you have said (see my first comment) your processing needs multiple threads and will run almost continuously.  What has sending sms got to do with a browser timeout ?
0
 
bbkevinAuthor Commented:
Hi Andy,
The poor SMS API will error, it is not able to handle too much request on the same times..
Any easy way to call in one by one?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Copied from my first comment:

>>Approximately 100,000 mobile numbers need to send each day
>>Each API call take about 5 seconds

By my reckoning that is over 13 days of work being done per day !!  

>>>>The poor SMS API will error, it is not able to handle too much request on the same times..
Looks like you have an impossible task for one PC in that case.  You require multiple PC's, each processing a smaller number of the phone numbers.
0
 
bbkevinAuthor Commented:
Hi Andy,
just assume there will be 1000 mobile numbers...
Is it possible to use Async?
That is, When I click the Start button, the program will call the method on the Web Service asynchronously and will not wait for the result / call back, then the webpage will disable the STARt button and display the message "Processing is running"....

The below statements will become a Web Service method
SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandText = "SELECT ClientName, MobileNumber FROM SMSList";
            conn.Open();
            SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                EESMSAPI objEE = new EESMSAPI();
                bool result = objEE.SendSMS(reader["ClientName"].ToString(), reader["MobileNumber"].ToString());

                using (SqlConnection conn2 = new SqlConnection(connectionString))
                {
                    SqlCommand comm2 = new SqlCommand();
                    comm2.Connection = conn2;
                    comm2.CommandText = "Update SMSList SET Result = @Result, SendDate = GETDATE() WHERE MobileNumber = @MobileNumber";
                    conn2.Open();
                    comm2.Parameters.AddWithValue("@Result", result);
                    comm2.Parameters.AddWithValue("@MobileNumber", reader["MobileNumber"].ToString());
                    comm2.ExecuteNonQuery();
                }
            }
            reader.Close();

Open in new window


0
 
AndyAinscowFreelance programmer / ConsultantCommented:
From an earlier comment by you:
The poor SMS API will error, it is not able to handle too much request on the same times..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.