积极答复者
使用WebClient类取内容,多次取内容的时候,程序闪退。

问题
答案
-
把不必要的capabilities取消勾选之后,在520运行多次,没有出现闪退。
另外,我想你的闪退问题应该出在定时器触发web请求这块儿,把定时器用后台代理替换试试
- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月13日 3:28
-
应该也不是后台代理的问题,我仔细看了一下你的代码,你在请求回调方法中应该对e.Error做一定检测:
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
using (StreamReader reader = new StreamReader(e.Result))
{
string contents = reader.ReadToEnd();
int begin = contents.ToString().IndexOf("low");
int end = contents.ToString().IndexOf("vol");
textblock1.Text = contents.ToString().Substring(begin + 5, end - begin - 7);
///////////////////////////////////////////////////////////- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月13日 3:27
全部回复
-
把不必要的capabilities取消勾选之后,在520运行多次,没有出现闪退。
另外,我想你的闪退问题应该出在定时器触发web请求这块儿,把定时器用后台代理替换试试
- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月13日 3:28
-
应该也不是后台代理的问题,我仔细看了一下你的代码,你在请求回调方法中应该对e.Error做一定检测:
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
using (StreamReader reader = new StreamReader(e.Result))
{
string contents = reader.ReadToEnd();
int begin = contents.ToString().IndexOf("low");
int end = contents.ToString().IndexOf("vol");
textblock1.Text = contents.ToString().Substring(begin + 5, end - begin - 7);
///////////////////////////////////////////////////////////- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月13日 3:27