小白求教,DispatcherTimer定时刷新问题。。。
小弟现在想让 手机 从某个网站定时 提取数据,并在一个textbox中显示出来。。然后代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.Windows.Threading;
namespace WebClientHttpWebRequest
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(10);
timer.Tick += timer_Tick;
timer.Start();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
DoWebClient();
}
private void DoWebClient()
{
}
void timer_Tick(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.OpenReadAsync(new Uri("http://quote.zhijinwang.com/xml/ag.txt"));
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
}
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
using (StreamReader reader = new StreamReader(e.Result))
{
string contents = reader.ReadToEnd();
int begin = contents.ToString().IndexOf("t");
int end = contents.ToString().IndexOf("&");
webClientTextBlock.Text = contents.ToString().Substring(begin + 5, end-begin-5 );
string[] arry = contents.Split('|');
string note =arry[arry.Length - 8];
textBox1.Text = note;
}
}
}
}