using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;
namespace prjDownLoad
{
class Program
{
//添加一个AutoResetEvent
//这是一个信号机
static AutoResetEvent are = new AutoResetEvent(false);
static void Main(string[] args)
{
//Version8.0
//将下载数据放入线程池中。
ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadData));
//等着,直到有人通知说俺可以继续。
are.WaitOne();
Console.WriteLine("俺可以干其他的活了。");
//去掉俺最不喜欢的Console.ReadLine
//程序运行到这里为什么需要Console.ReadLine?
//因为现在如果直接结束主线程,那么异步回来的数据
//就没人接收了。
//为什么要去掉Console.ReadLine呢?
//你以为谁都像你一样的做的都是控制台应用程序?!
//Console.ReadLine();
}
//把这个方法加一个object参数,这是WaitCallback要求的
static void DownloadData(object obj)
{
//不光WebResponse的获得使用异步方式
//连读取数据都使用异步方式。
//创建WebRequest对象