对于轻量级的网络内容获取在Windows Phone上可以采用WebClient类在System.Net.WebClient这个命名空间中,相对于HttpWebRequest类而言WebClient工作在UI线程中,所以可能产生UI死锁问题,这里可以通过多线程的方式来解决。
class="brush:csharp;gutter:true;">Thread t = new Thread(new ThreadStart(ProcessWeb));
t.Start();
private void ProcessWeb()
{
WebClient wc = new WebClient();
wc.OpenReadCompleted += wcOpenReadCompleted;
wc.OpenReadAsync(new Uri("http://www.oschina.net/wp7"));
}
private void wcOpenReadCompleted(object sender, OpenReadCompletedEventArgs args)
{
if (!args.Cancelled && args.Error == null)
{
args.Result ; //这里保存着二进制结果。
}
}
详细说明:http://wp.662p.com/thread-8042-1-1.html