Henry581538

Hi.

when i need to load a file asynchronous,in c# how to write it

my program:

IXMLDOMDocument rssDom= new DOMDocument();

rssDom.async = true;

rssDom.onreadystatechange = // in javascript ,we write function(){;} but here

rssDom.load(url);

I tried delegate,but I got error message.

Thanks.



Re: Windows Forms General How to use IXMLDocument in C#?

TaylorMichaelL

You should not resort to the DOM. Instead use the .NET equivalent which is XmlDocument. Here is the same code in .NET

Code Snippet

Xmldocument doc = new XmlDocument();

doc.Load(url);

If you want to do this asynchronously then use the thread pool.

Code Snippet

ThreadPool.QueueUserWorkItem(LoadDocument, url);

void LoadDocument ( object state )
{

string url = state as string;

XmlDocument doc = new XmlDocument();

doc.Load(url);

//Set some sync object

}

Use a synchronization object like and event or mutex to let you know when it is done. Alternatively you can use an async method which has the notification built in.

Code Snippet

delegate XmlDocument AsyncLoad ( string url );

XmlDocument LoadXmlDocument ( string url )

{

XmlDocument doc = new XmlDocument();

doc.Load(url);

return doc;

}

//Later

AsyncLoad meth = new AsyncLoad(LoadXmlDocument);

IAsyncResult result = meth.BeginInvoke(url, null, null);

//Check later on

if (!result.IsCompleted)

{

//Or, block until it is done

result.AsyncWaitHandle.WaitOne();

};

//Handle results (will block until it is done)

XmlDocument doc = meth.EndInvoke(result);

Michael Taylor - 4/13/07

http://p3net.mvps.org





Re: Windows Forms General How to use IXMLDocument in C#?

Henry

thx so much,it helps