短信发送,利用多线程发布,其实很简单。开始,主线程每隔1秒去数据库读取待发信息。然后放入QUEUE有20个子线程,用来发送信息。从QUEUE中获取待发信息,然后发送。
现在的问题是,这个程序在XP和2000上都没有问题。但是在2003上,有时候会出现数据已经读取,但是没有发送出去,20个子线程好象没事做。200条信息记录会出现3到5条被卡住的情况。请各位大虾帮帮忙。
现在的问题是,这个程序在XP和2000上都没有问题。但是在2003上,有时候会出现数据已经读取,但是没有发送出去,20个子线程好象没事做。200条信息记录会出现3到5条被卡住的情况。请各位大虾帮帮忙。
myHttpWebRequest1.CookieContainer = Me.Cookies
Else
myHttpWebRequest1.CookieContainer = New Net.CookieContainer
Me.Cookies = myHttpWebRequest1.CookieContainer
End If Dim myRequestState As New xpasp_com.RequestState
myRequestState.request = myHttpWebRequest1
myHttpWebRequest1.AllowAutoRedirect = True
myHttpWebRequest1.ContentType = "application/x-www-form-urlencoded"
myHttpWebRequest1.Method = "POST"
myHttpWebRequest1.Timeout = 20 * 1000 Dim postStream As Stream = myHttpWebRequest1.GetRequestStream
Dim encoder As System.Text.Encoding = System.Text.Encoding.GetEncoding("gb2312")
Dim ByteArray As Byte() = encoder.GetBytes(postStr)
postStream.Write(ByteArray, 0, postStr.Length)
postStream.Close()
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest1.GetResponse(), HttpWebResponse) If tid = 0 Or CheckBox8.CheckState Then Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("gb2312")
'MsgBox(myHttpWebResponse.ResponseUri().ToString)
Dim streamRead As New StreamReader(streamResponse, enc)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
Console.WriteLine(ControlChars.Cr + "The contents of HTML Page are : ") Dim fs As New FileStream(selectPath & "\System\Temp\F1.htm", FileMode.Create)
Dim sw As New StreamWriter(fs, enc) While count > 0
Dim outputData As New [String](readBuff, 0, count)
Console.WriteLine(outputData)
sw.WriteLine(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While sw.Close()
fs.Close()
If CheckBox8.CheckState Then
Shell("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + selectPath & "\System\Temp\F1.htm", 1)
End If
streamResponse.Close()
streamRead.Close()
'allDone.WaitOne() End If
myHttpWebResponse.Close()
谢谢!TO:夕阳轨迹
这段代码不是很适合我,谢谢TO:soaringbird
我是用网关发送,由于对方是ASP,可以使用多线程。业务上的需要,有时候是批量发送短信的,所以得开多线程。谢谢TO: 起步停车
代码调试中,短信未发送出去,而且我每次发送短信都是从QUEUE中获取的。即是说,线程要发送的短信,是从QUEUE里面PUSH出来的。
我试试看,谢谢。TO:soaringbird
有加锁。谢谢
2 你的发送代码是从哪里来的?自己写的或别人提供的?如别人提供的有没有限制条件?
发送代码是否运行?有无异常抛出?
20个线程一直在跑,“卡住”后,如果再插入新数据,也会发送,但是就有那么几个,3到5个会“卡住”。TO helloworld
我也在考虑不要用队列,但是不用队列,每个线程都去访问数据库的话,数据库负担很重啊。