It looks like the problem is that your AddUpdateObservableCollection
method sees that the tasks
collection is empty, and then exits.
If you want it to be persistent, replace your foreach
with:
foreach (StockModel sm in tasks.GetConsumingEnumerable())
The enumerator you get from GetConsumingEnumerable will block waiting on items to be added to the queue, and will continue to block until the other thread marks the collection as complete for adding. So when you're done adding things to the queue and want the AddUpdateObservableCollection
method to exit, just call tasks.CompleteAdding()
. The loop will empty the queue, see that no more items are forthcoming (because the IsAddingCompleted
property is true
), and exit.
I'm a little confused about how you're getting things into the blocking collection, though. Your code snippet isn't too clear. If you're having trouble with that, edit your question and explain what the problem is. The comment in the code for handlermethod
is pretty cryptic.