开发者

How to make values transfer between multiple threads

I have two threads:

Thread 1 is fetching XML from a web service in loop.

Thread 2 is parsing the XML fetched by thread 1 and开发者_如何学Go showing it in the UI.

Please tell me what is the best way to pass XML data from thread 1 to thread 2 as it’s retrieved by thread 1?

Thread 1 is fetching the XML and then thread 2 consuming it.

To do so i have created a circular linked list and thread 1 puts its XML there in the linked list and thread 2 gets the XML for it and remove it from the list, and it’s working fine.

Please tell me if there is any other better approach than what I am using.


Looks like you need

Producer-Consumer Quequ


The framework provides

ConcurrentQueue

with .NET 4.0. It should implement a queue between consumer and producer without the need of any manual synchronisation.


If you are on .Net 4.0 you can use BlockingCollection, this is a Producer-Consumer Queue which allows the consumer to wait for more work from the producer without you having to manage the interaction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜