-
August 11th, 2009, 02:22 PM
#1
Getting an object from a different thread
Ok, I've done some googling, searched these forums, but I couldn't find the answer to my problem. So here it is:
I've got a function in a class that creates a new thread which creates an XMLDocument object and downloads data into it. After it is finished it should somehow pass on that XMLDocument to the main thread (that runs the class, so to speak) so I can get data from it.
So I don't have to access any data while the thread is running, if that makes a difference (and I think it does, from what I've seen so far).
So far the only code I've got working is the code without sharing the XMLDocument when finished, and it is this:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
namespace Lolcats
{
class LolcatsRss
{
private string url = "http://this/is/my/rss/url";
XmlDocument xmlDoc;
Thread webThread;
public LolcatsRss()
{
Thread webThread = new Thread(new ThreadStart(getRss));
webThread.Start();
}
public void getRss() {
XmlDocument _xmlDoc = new XmlDocument();
_xmlDoc.Load(url);
}
}
}
I've tampered with some delegates, but nothing that didn't throw a theading-related exception, so obviously not the right way. Who can enlighten me?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|