 |
建站必读 |
 |
|
|
 |
|
 |
|
| |
| 当前位置:首页 -> 建站必读 -> .NET技术 |
|
线程池跟自定义事件的应用例子 |
using System;
using System.Threading;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace ThreadPoolDelegate
{
//public delegate void ReceiveCompletedEventHandler(string url,string title,string sourcecode);
public delegate void ReceiveCompletedEventHandler(object sender,ReceiveCompletedEventArgs e);
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1
{
public event ReceiveCompletedEventHandler ReceiveCompletedEvent;
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void ReadSourceCode(object o)
{
string url = (string)o;
string title = "";
string sourcecode = "";
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(url);
sourcecode = Encoding.Default.GetString(data);
title = this.GetPageTitle(sourcecode);
if (ReceiveCompletedEvent != null)
{
//ReceiveCompletedEvent(url,title,sourcecode);
ReceiveCompletedEvent(this,new ReceiveCompletedEventArgs(url,title,sourcecode));
}
}
public void ReadSourceCode(object o,bool timeout)
{
string url = (string)o;
string title = "";
string sourcecode = "";
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(url);
sourcecode = Encoding.Default.GetString(data);
title = this.GetPageTitle(sourcecode);
if (ReceiveCompletedEvent != null)
{
|
| |
|
| |
本站关键词: |
|
|
|
|
 |
|
 |
|