title: Why is it slow to refresh ObservableCollection in DataGrid
body: <p>I need to process 4000 message packets every second, from a total of 80 different IDs. I have a <code>DataGrid</code>. I have <code>ObservableCollection</code> binded to DataGrid. I tried 2 ways to refresh the UI without freezing. I was unsuccessful in both.</p>
  <p><strong>1.Way</strong></p>
  <p>If there is a message from a different ID, I add it to my collection. If it comes from the same ID, I delete the old one and get the new one.</p>
  <pre><code>          if (MessagePacket._jobs.Where(X =&gt; X.ID == dataPacket.ID).FirstOrDefault() == null)
              {
                  MessagePacket._jobs.Add(dataPacket);
              }
              else
              {
                  for (int x = 0; x &lt; MessagePacket._jobs.Count; x++)
                  {
                      if (MessagePacket._jobs[x].ID == dataPacket.ID)
                      {
                           MessagePacket._jobs.RemoveAt(x);
                           MessagePacket._jobs.Add(dataPacket);
                      }              
                  }
              }
  </code></pre>
  <p><strong>2.Way</strong></p>
  <p>I am modifying the data without deleting it and refreshing the collection.</p>
  <p><em><strong>Note</strong></em> : I tried to refresh the collection every 50ms, not after every pack. It's still slow.</p>
  <pre><code>        if (MessagePacket._jobs.Where(X =&gt; X.ID == dataPacket.ID).FirstOrDefault() == null)
              {
                  MessagePacket._jobs.Add(dataPacket);
              }
              else
              {
                  for (int x = 0; x &lt; MessagePacket._jobs.Count; x++)
                  {
                      if (MessagePacket._jobs[x].ID == dataPacket.ID)
                      {
                          MessagePacket._jobs[x].DLC = dataPacket.DLC;
                          MessagePacket._jobs[x].RTR = dataPacket.RTR;
                          MessagePacket._jobs[x].IDE = dataPacket.IDE;
                          MessagePacket._jobs[x].Byte0 = dataPacket.Byte0;
                          MessagePacket._jobs[x].Byte1 = dataPacket.Byte1;
                          MessagePacket._jobs[x].Byte2 = dataPacket.Byte2;
                          MessagePacket._jobs[x].Byte3 = dataPacket.Byte3;
                          MessagePacket._jobs[x].Byte4 = dataPacket.Byte4;
                          MessagePacket._jobs[x].Byte5 = dataPacket.Byte5;
                          MessagePacket._jobs[x].Byte6 = dataPacket.Byte6;
                          MessagePacket._jobs[x].Byte7 = dataPacket.Byte7;
                          MessagePacket._jobs[x].Time = DateTime.Now.ToString(&quot;HH:mm:ss&quot;);
                          CollectionViewSource.GetDefaultView(MessagePacket._jobs).Refresh();
  
                      }
                  }
              }
  </code></pre>
  <p>How can I speed up the up processes without freezing the ui. Or can you show an alternative way? Thank you from now.</p>