vb.net多线程采集 vb6多线程处理
VB6.0 实现怎么多线程 主线程用户界面 辅助线程用来数据采集
VB6的多线程非常差,虽然可以用API创建线程,但是会非常不稳定,而且VB6.0用API创建的线程不能对控件进行操作,否则会当场崩溃,我建议你使用VB.NET去进行多线程编写。
成都创新互联公司是一家专注于网站制作、网站设计与策划设计,门头沟网站建设哪家好?成都创新互联公司做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:门头沟等地区。门头沟做网站价格咨询:13518219792
VB.NET 简单多线程
多线程一般是不推荐用的,因为线程之间如果有共享资源的话会引起竞争,需要加锁处理;而且线程间没有时序关系,所以你在调试中可能会出现异步处理结束顺序与开始处理顺序不一致的情况(我在调试中已经发现该问题)。
针对你提出的这个问题,采用了多线程处理,利用的是BackgroundWorker也就是异步处理控件进行了处理。
代码已经经过调试通过。欢迎交流,如有问题,留下QQ或其他联系方式。
代码如下,并附程序截图。
‘---------------------------------------------------
Imports System.ComponentModel '导入异步控件命名空间
Public Class Form1
Private howmany As Integer = 10
Private AnalysisNumber(0 To howmany - 1) As BackgroundWorker
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
creatNewBackgroundWorker()
addHandle()
startWork()
End Sub
Private Sub creatNewBackgroundWorker()
For i As Integer = 0 To AnalysisNumber.Length - 1
AnalysisNumber(i) = New BackgroundWorker
Next
End Sub
Private Sub addHandle()
For i As Integer = 0 To AnalysisNumber.Length - 1
AddHandler AnalysisNumber(i).DoWork, AddressOf AnalysisNumber_DoWork
AddHandler AnalysisNumber(i).RunWorkerCompleted, AddressOf AnalysisNumber_RunWorkerCompleted
Next
End Sub
Private Sub startWork()
For i As Integer = 0 To 9
Dim temp(0 To 9) As Integer
For j As Integer = 1 To 10
temp(j - 1) = 10 * i + j
Next
AnalysisNumber(i).RunWorkerAsync(temp)
Next
End Sub
Private Sub AnalysisNumber_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim data As Integer()
data = CType(e.Argument, Integer())
Dim temp As Integer
For i As Integer = 0 To data.Length - 1
temp = data(i)
data(i) = temp * temp
Next
e.Result = data
End Sub
Private Sub AnalysisNumber_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
Dim data As Integer()
data = CType(e.Result, Integer())
For i As Integer = 0 To data.Length - 1
ListBox1.Items.Add(data(i))
Next
End Sub
End Class
vb.net 多线程获取网页内容
public static string getXmlFile(String url, String paramList,string referer)
{
HttpWebResponse res = null;
string strResult = " ";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET ";
req.KeepAlive = true;
req.Referer=referer;
//CookieContainer cookieCon = new CookieContainer();
//req.CookieContainer = cookieCon;
//req.CookieContainer.SetCookies(new Uri(url),cookieheader);
StringBuilder UrlEncoded = new StringBuilder();
res = (HttpWebResponse)req.GetResponse();
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding( "gb2312 ");
StreamReader sr = new StreamReader( ReceiveStream, encode );
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
while (count 0)
{
String str = new String(read, 0, count);
strResult += str;
count = sr.Read(read, 0, 256);
}
}
catch(Exception e)
{
strResult = e.ToString();
}
finally
{
if ( res != null )
{
res.Close();
}
}
return strResult;
}
多线程里调用就行了 费了好长时间才弄出来 我调试过了 能行 如果对你有用就给分吧
网页标题:vb.net多线程采集 vb6多线程处理
本文地址:http://pwwzsj.com/article/hhcdcs.html