在C#中,如何在一段时间后显示与XML不同的属性?

在C#中,如何在一段时间后显示与XML不同的属性?,c#,xml,yahoo-api,C#,Xml,Yahoo Api,我正在开发一个windows窗体应用程序C#,它将显示新闻标题。到目前为止,我只能展示第一个标题。我希望我的应用程序在20秒后显示下一个标题,以此类推。如果我的头衔用完了,它会再次回到榜首。到目前为止,我已经做到了: private void GetNewsTopStories() { string queryNews = String.Format("http://news.yahoo.com/rss/"); XmlDocument wData = new XmlDocumen

我正在开发一个windows窗体应用程序C#,它将显示新闻标题。到目前为止,我只能展示第一个标题。我希望我的应用程序在20秒后显示下一个标题,以此类推。如果我的头衔用完了,它会再次回到榜首。到目前为止,我已经做到了:

private void GetNewsTopStories()
{
    string queryNews = String.Format("http://news.yahoo.com/rss/");
    XmlDocument wData = new XmlDocument();
    wData.Load(queryNews);

    XmlNamespaceManager manager = new XmlNamespaceManager(wData.NameTable);

    XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");
    XmlNodeList nodes = wData.SelectNodes("rss/channel/item", manager);

    titleNews = channel.SelectSingleNode("item").SelectSingleNode("title").InnerText;
    topNewsLabel.Text = titleNews.ToString();
}
试试这个

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        const string URL = "http://news.yahoo.com/rss/";
        string[] titles = null;
        int count = -1;
        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = false;
            timer1.Tick += new System.EventHandler(this.timer1_Tick);
        }

        private void buttonEnd_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            timer1.Interval = 20000;
            count = -1;
            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if ((count == -1) || (count >= titles.Count()))
            {
                GetFeeds();
                count = 0;
            }
            textBox1.Text = titles[count++];

        }
        public void GetFeeds()
        {
            timer1.Enabled = false;
            XDocument doc = XDocument.Load(URL);
            titles = doc.Descendants("item").Select(x => (string)x.Element("title")).ToArray();
            timer1.Enabled = true;
        }
    }


}
试试这个

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        const string URL = "http://news.yahoo.com/rss/";
        string[] titles = null;
        int count = -1;
        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = false;
            timer1.Tick += new System.EventHandler(this.timer1_Tick);
        }

        private void buttonEnd_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            timer1.Interval = 20000;
            count = -1;
            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if ((count == -1) || (count >= titles.Count()))
            {
                GetFeeds();
                count = 0;
            }
            textBox1.Text = titles[count++];

        }
        public void GetFeeds()
        {
            timer1.Enabled = false;
            XDocument doc = XDocument.Load(URL);
            titles = doc.Descendants("item").Select(x => (string)x.Element("title")).ToArray();
            timer1.Enabled = true;
        }
    }


}