I am using a service that someone else has written that gets market data. It connects to their server and you send it a symbol and it sends back data. Well I am trying to use it to have multiple Views open so you can get market data for more than one symbol. The way this is done is that my ViewModel subscribes to the singleton event IncomingMessage and if the message contains the ViewModel’s symbol it puts it into an ObservableCollection. And that’s where the problem is.
How can I add the message from the event to my collection safely?
[Edit]
I believe the exception is being thrown because my ObservableCollection is bound to a DataGrid on my view.
You need to marshal the call to the Add method to the UI thread. In Prism this is usually done with the event aggregator, but if you are not using prism:
Assuming you have some type
Tickthat represents your market data, and that the data event is just aSystem.Action<Tick>:or, simply