I'm trying to add a listener that adds the price of a stock to a ListView every time it receives a price update from the WebSocket. My code is as follows:
private void Ws_OnMessage(object sender, MessageEventArgs e)
{
dynamic data = JsonConvert.DeserializeObject<dynamic>(e.Data);
double price = data["data"][0]["p"];
string stock = data["data"][0]["s"];
Console.WriteLine(stock + " " + price.ToString());
string[] arr = {stock, price.ToString()};
ListViewItem itm = new ListViewItem(arr);
portfolioList.Items.Add(itm);
}
When I run this, however, the price is successfully received, but the list is not updated, and instead, the console throws a System.InvalidOperationException.