I use a third-party library that iterates over very large flat files, which can take many minutes. The library provides an Enumerator, so you can give each result and process it, while the counter then extracts the next element in a flat file.
eg:
IEnumerable<object> GetItems() { var cursor = new Cursor; try { cursor.Open(); while (!cursor.EOF) { yield return new
What I'm trying to achieve is to have two consumers of the same Enumerable, so I donβt need to retrieve the information twice so that each consumer can process each item as it arrives, without waiting for the time to arrive immediately.
IEnumerable<object> items = GetItems(); new Thread(SaveToDateBase(items)).Start(); new Thread(SaveSomewhereElse(items)).Start();
I guess what I'm trying to achieve is something like
"if the item that the consumer is requesting is already extracted, then it returns it, otherwise move on and wait," but I am aware of the possible collisions of MoveNext () between the two threads.
Something like this is already coming out if you donβt think how it will be achieved?
thanks
source share