-1

We get messages[as key-value pair] from the real time server in milli second intervals.

So basically, we send a list of tickers and every milli second, we get the response from the real time service as key-value pairs(ticker-price) that we need to display at the UI. We are using wpf datagrid to display data. In order to throttle the incoming messages, I was thinking that if the price received is the same as that displayed at the UI, we can ignore it. As flushing all these messages to the ui will slow down the performance.

Also, we may need some data structure to store the incoming messages, before pushing it to the UI. Can you suggest, what would be a good data structure to temporarily save these messages before flushing to UI.

Also,can you please guide me what would be the best approach for such a situation?

Thanks in advance.

1 Answers1

0

For the connection between the data and the UI I would use a simple class as datamodel and then use the MVVM model to bind an ObservableCollection to your wpf DataGrid

Every time an item is received, you could push it to the Collection and the setter could check if an actual change of the collection is desired.

If wanted, you could also do this check before you add the item to the collection.

very basic example:

class ViewModel0
{
    private ObservableCollection<Item> items;

    public ObservableCollection<Item> Items
    {
        get { return items; }
        set
        {
            if (//implement check if the new item needs to be pushed to the list here)
            {
                items = value;
                NotifyPropertyChanged();
            }

        }
    }

    public void addNewEntry(string value1, string value2)
    { 
        Item newItem = new Item(value1, value2);
        Items.Add(newItem);
    }

    public void addNewEntryWithCheck(string value1, string value2)
    {
        if (//implement check if the new item needs to be pushed to the list here)
        {
            Item newItem = new Item(value1, value2);
            Items.Add(newItem); 

        }
    }

}

you could also just discard the datamodel and directly implement the KeyValuePair into your collection

class ViewModel1
{
    private ObservableCollection<KeyValuePair<string, string>> myVar;

    public ObservableCollection<KeyValuePair<string, string>> MyProperty
    {
        get { return myVar; }
        set
        {
            if (//implement check if the new item needs to be pushed to the list here)
            {
                myVar = value;
                NotifyPropertyChanged();
            }

        }
    }

    public void addNewEntry(KeyValuePair<string, string> newEntry)
    {
        MyProperty.Add(newEntry);
    }

    public void addNewEntryWithCheck(KeyValuePair<string, string> newEntry)
    {
        if (//implement check if the new item needs to be pushed to the list here)
        {
            MyProperty.Add(newEntry);
        }
    }

}
ImP
  • 175
  • 1
  • 4
  • 12
  • Thanks for the quick solution. However, the messages move in at the rate of 300M per second. I think we may need some throttling mechanism, or else the UI will keep painting and may not be responsive. – user1896549 Dec 01 '15 at 20:35
  • As long as no change is made, NotifyPropertyChanged will not be called and the UI will not change. Edit: maybe only check a maximum of 60 times /s for the last new entry, or even 5. Kind of all depends on what data you find important enough to display – ImP Dec 02 '15 at 00:09