using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Threading;
using
System.Net;
using
System.IO;
using
System.Collections;
using
System.Diagnostics;
namespace
SendSMSThreading
{
public partial class Form1 : Form
{
static readonly object padlock = new object();
Connection objCon = new Connection();
int NumberOfThread = 10;
public Form1()
{
InitializeComponent();
}
private void SendSMS1(DataRow dr_SMS)
{
lock (padlock)
{
try
{
string qry = "http://144.56.58.164:80/login/pushsms.php?login=XXXXXXXXX&pass=XXXXXXXXXX&sender_name=" + dr_SMS["SenderID"].ToString() + "&mob_no=91" + dr_SMS["MobileNo"].ToString() + "&text=" + dr_SMS["Text"].ToString();
WebRequest wReq = WebRequest.Create(qry);
WebResponse wResp = wReq.GetResponse();
Stream respStream = wResp.GetResponseStream();
StreamReader reader = new StreamReader(respStream);
String respHTML = reader.ReadToEnd();
wResp.Close();
Connection.UpdateStatus_SMSLogThread1("Delivered", Convert.ToInt32(dr_SMS["ID"]));
}
catch (Exception ex)
{
Connection.UpdateStatus_SMSLogThread1("Failed", Convert.ToInt32(dr_SMS["ID"]));
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled =
false;
ProcessThreadCollection threadcol = Process.GetCurrentProcess().Threads;
if (threadcol.Count < NumberOfThread )
{
DataTable dt_SMS = objCon.SelectRecord_FromSMSlogThread1();
if (dt_SMS == null || dt_SMS.Rows.Count <= 0)
{
timer1.Enabled =
true;
return;
}
else
{
foreach (DataRow dr in dt_SMS.Rows)
{
Thread SMSThread = new Thread(delegate()
{
SendSMS1(dr);
}
);
SMSThread.Start();
Thread.Sleep(120);
}
}
}
timer1.Enabled =
true;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(0, 60);
NumberOfThread = objCon.GetNumberOfThreads();
btnStart_Click(
null, null);
}
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Enabled =
true;
btnStart.Enabled =
false;
btnStop.Enabled =
true;
}
private void btnStop_Click(object sender, EventArgs e)
{
btnStop.Enabled =
false;
timer1.Enabled =
false;
btnStart.Enabled =
true;
}
}
}
Please test my code is it workable or not
What I m Doing here ---
I have created a project in which User can send SMS ,AS user send SMS it stores in my database. Now I read the sms from database and send sms to my provider . I have to fire the api .I need good speed so I use Thread but the speed is not satisfactory Please Help me .