Reputation: 2115
I'm new to C#/.NET programming and I have a question.
I use BackgroundWorker
to fetch XML data from server.
The problem is that data is paginated. After I get a page I should check if there are another page available and fetch it next.
But I don't want to make the user wait till (dozen or more) pages will be loaded. And I can't make parallel requests to server due API ToS (and I don't know how many pages are there).
What I want is to display (via DataGridView) each page of data as soon as possible. Some kind of pseudo-yield
.
Is it possible with BackgroundWorker
or I have to use something else (I use .NET 4, VS2012)
Upvotes: 0
Views: 113
Reputation: 2267
You should call the public void ReportProgress(int percentProgress,Object userState)
method with the XmlNode
segment as your state object each time your background worker retrieves a page. This will trigger the ProgressChanged
event.
Keep the worker running until you run out of pages. Here's an example: http://msdn.microsoft.com/en-us/library/vstudio/ywkkz4s1.aspx
Upvotes: 1