Edward
Edward

Reputation: 7424

Loading content from an xml file using a background thread?

I've run into a situation with loading content from an xml file. Basically there can very well be hundreds of items in one of these xml files at a time. Now when I navigate to a page I have to databind these objects to a listbox control and display them to a user. Now I was using the OnNavigatedTo Event and was loading the content using LINQ. The problem was as more items were added to the xml file, the page started taking longer to load.

Then I waited until I navigated to the page and it was displayed to call the xml file, but the UI became unresponsive for about a second and a half.

So the thought that came to my mind was to see if there was someway to load the xml file on a background thread so that it doesn't affect the UI. Is this possible, and if so can you point me to a resource where I can get some more info.

Upvotes: 3

Views: 591

Answers (1)

Kevin Gosse
Kevin Gosse

Reputation: 39007

BackgroundWorker is exactly what you need: http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

Basically, it executes the DoWork method in a background thread, then executes the WorkerCompleted method where you can update the UI with the result of the calculations.

Upvotes: 4

Related Questions