Q:

Program locks up when reading RSS feed

I've made myself a class that reads RSS feeds and returns them to my main class.  The code that I use for this is:
public List<Post> getLatestPosts()
{
    this.rssReader = new XmlTextReader(this.rssUrl);
    this.rssDoc = new XmlDocument();

    // Load the XML content into rssDoc
    rssDoc. Load(rssReader);

    // ... other code to parse XML ... //
}

Now, when I call getLatestPosts() my application locks up for a few seconds.  I'm assuming it's because that's how long it takes for the application to request the RSS feed (network latency and so forth). 
I want to change this so my program doesn't lock up, and instead just waits for the response.  I had the idea of using threads in my main form, but I'm confused about how I can capture whatever RSS data getLatestPosts() gets. 
If I do this in my button click on my main form:
private void bGetLatestPosts_Click(object sender, EventArgs e)
{
    Thread thread = new Thread(new ThreadStart(rssReader.getLatestPosts()));
}

I'm not capturing anything that getLatestPosts() returns. 
I'm completely new to threads (this is mostly just me messing around to try and learn them) but I do have some experience in C#. 
Thanks. 

A:

I'm assuming you are writing a WinForms application.  There are two important rules for writing responsive WinForms applications:

Everything you do on the do on the main UI thread should complete quickly. 
You can't access controls from any thread other than the main thread. 

To solve your problem, run your code in a BackgroundWorker. 

The BackgroundWorker class allows you to run an operation on a separate, dedicated thread.  Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running.  When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution. 
To execute a time-consuming operation in the background, create a BackgroundWorker and listen for events that report the progress of your operation and signal when your operation is finished.  You can create the BackgroundWorker programmatically or you can drag it onto your form from the Components tab of the Toolbox.  If you create the BackgroundWorker in the Windows Forms Designer, it will appear in the Component Tray, and its properties will be displayed in the Properties window. 
To set up for a background operation, add an event handler for the DoWork event.  Call your time-consuming operation in this event handler.  To start the operation, call RunWorkerAsync.  To receive notifications of progress updates, handle the ProgressChanged event.  To receive a notification when the operation is completed, handle the RunWorkerCompleted event. 

Here's some code that might help you:
private void bGetLatestPosts_Click(object sender, EventArgs e)
{
    bGetLatestPosts. Enabled = false;
    backgroundWorker. RunWorkerAsync();
}

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
    e.Result = getLatestPosts();
}

private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    if (e.Error ! = null)
    {
        // Handle exception...
    }
    else
    {
        List<Post> result = (List<Post>)e. Result;
        // Update GUI...
    }
    bGetLatestPosts. Enabled = true;
}

