3

I have a list that is bound to a blockingcollection in my viewmodel

<ListBox Grid.Row="1" ItemsSource="{Binding PlantControllers}"

and property

  public BlockingCollection<PLANTCONTROLLER> PlantControllers
        {
            get { return _plant.PlantControllers; }

        }

What is the easiest way of making a blockingcollection observable, cant seem to find any good examples out there

klashagelqvist
  • 1,251
  • 2
  • 26
  • 52

1 Answers1

2

Use your BlockingCollection as an "entry point" for data going into your UI thread using a producer/consumer pattern.

Your threads all add items to the BlockingCollection, and on your UI thread use a timer to occasionally check to see if there are new items. If there are, take them and add them to an ObservableCollection.

Another option could be to have each thread have a reference to the UI thread's dispatcher, and use Dispatcher.BeginInvoke() to queue up the method that takes from the BlockingCollection and adds to the ObservableCollection.

Steve
  • 6,334
  • 4
  • 39
  • 67