Click here to Skip to main content
13,344,508 members (49,563 online)
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 7 Apr 2007

Windows RSS Reader Application Using Threads

Rate this:
Please Sign up or sign in to vote.
In this article, you will learn how to create an asynchronous RSS reader Windows application (using threads).

Screenshot - AsynchronousRSSReader.jpg


In this article, you will learn how to create an Asynchronous RSS reader Windows application. The application will connect to a web server and retrieve required information from that web server. Reading RSS information from a web server is such an easy job! To do that, you just need to find a proper web server that gives you the information you're looking for and then get those information just by following a link! For example, take a look at this link.

By clicking the link, you will see the RSS of CodeProject. This RSS gives you the latest CodeProject articles. So, you can use this information in your website or your Windows application. The content of an RSS is nothing but XML and you just need to get that XML and manipulate it.


To retrieve RSS data, you just need a DataSet! First, you have to declare it:

DataSet DTS = new DataSet();

And to read RSS data, you need to do something like this:


Just that! And, you have a DataSet that is filled with appropriate data to manipulate! But there is a really big problem! While your application is retrieving data from the server, your application will not respond until the transfer of the data is completed. To solve the problem, you need to do all of these in an asynchronous way. You can use threads, and call the method which retrieves data in another thread. Here is the method which gets data in an asynchronous way:

private void BeginGetData(string RssLink, ListView lstView, string WebServer)
    ArrayList arl = new ArrayList();

    ParameterizedThreadStart TSS = new ParameterizedThreadStart(GetRSSData);
    Thread Thread1 = new Thread(TSS);

As you can see, it gets a link to the RSS server and a list view to represent the data in it and the name of the RSS server. To send those data to a thread, you need to put them all in an object data type. So, an instance of ArrayList has been created to hold the values. After that, you just need to declare the thread and send the object to it. As you can see in the code above, the method that is used by the thread is called GetRSSData.

private void GetRSSData(Object Parameters)
    ArrayList ar = (ArrayList)Parameters;
    string rsslink = ar[0].ToString();
    ListView lst = (ListView)ar[1];
    string WebServer = ar[2].ToString();

    DataSet DTS = new DataSet();
            MessageBox.Show("Error getting data from server", 
                            "Error", MessageBoxButtons.OK, 

    ShowInfo(DTS, lst, WebServer);

In the GetRSSData, first the data that has been sent to the method is unpacked, and then the RSS link has been retrieved by this line of code:


After that, you just need to show the data, but here is another problem. You can't do that in the normal way. Because, the ListView you're trying to put the data in is not created in this thread. Only the thread that has created the ListView can manipulate it. So, you need to use another method:

delegate void ShowInfoCallback(DataSet dataset, ListView lstView, string WebServer);
private void ShowInfo(DataSet dataset, ListView lstView, string WebServer)
    if (lstView.InvokeRequired)
        ShowInfoCallback d = new ShowInfoCallback(ShowInfo);
        this.Invoke(d, new object[] { dataset, lstView, WebServer });
        //Processing the data


This method looks for the owner thread of the ListView. If the thread that is executing this method is the owner thread of the ListView, the data processing will occur:

DataTable tbl = new DataTable();
if (WebServer == "codeproject")
    tbl = dataset.Tables[3];
else if (WebServer == "microsoft")
    tbl = dataset.Tables[2];
else return;


for (int i = 0; i < tbl.Rows.Count; i++)
    ListViewItem item = new ListViewItem(tbl.Rows[i]["title"].ToString());

    if (WebServer == "codeproject")
    else if (WebServer == "microsoft")
    item.Tag = tbl.Rows[i]["link"];

So, to read any kind of RSS data, you just need to call the BeginGetData method by providing the appropriate RSS link to it, but you may need to change some parts of the code in the ShowInfo method.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mohammad Akbarizadegan
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of) developer

You may also be interested in...


Comments and Discussions

Generaltashakor Pin
narmafzarboy25-May-07 2:35
membernarmafzarboy25-May-07 2:35 
GeneralSuggestion Pin
Alireza . Shirazi9-Apr-07 4:40
memberAlireza . Shirazi9-Apr-07 4:40 
GeneralGood Work Pin
Syed M Hussain8-Apr-07 12:33
memberSyed M Hussain8-Apr-07 12:33 
Just want to say good tutorial. Easy for beginners in my opinion.Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 7 Apr 2007
Article Copyright 2007 by Mohammad Akbarizadegan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid