0

I am developing a C# application, where I get USB data every 1 millisecond and my application has a data grid which is intended to display these frames as soon as its received. My problem here is since data rate is too high my grid stops or application freezes after 10-15 seconds of launching. I have created separate thread to handle this displaying part even though it does'nt help me. Is the data grid capable enough to display data at 1ms rate? Should I use some other way to make it working? Any help, hints or suggestion would be of great help. Thank you.

Code: The gui() function is made as thread and datatable is passed as a parameter. The data which is received by the driver underneath adds the data to datatable and then passed as a param for gui() funtn.

    public static DataView dataview = new DataView();
    public static void gui(DataTable dt)
    {
         try
            {
                if (dt != null)
                {
                    lock (Lock)
                    {
                                                   Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate()
                        {
                            main.dgUsers.ItemsSource = null;
                            dataview = dt.DefaultView;
                            main.dgUsers.ItemsSource = dataview;
                            main.dgUsers.Items.Refresh();


                            //For auto scroll through the data grid
                            if (main.dgUsers.Items.Count > 0)
                            {
                                var border = VisualTreeHelper.GetChild(main.dgUsers, 0) as Decorator;
                                if (border != null)
                                {
                                    var scroll = border.Child as ScrollViewer;
                                    if (scroll != null) scroll.ScrollToEnd();
                                }
                            }
                        }));
                    }
                }
         }

         catch (Exception e)
         {
             MessageBox.Show(e.Message);
         }
    }
shravan
  • 21
  • 4
  • Can you show some initial code you already tried? – janonimus Apr 13 '17 at 05:53
  • 1ms. Can't you send second request when first one finishes.? – Nikhil Agrawal Apr 13 '17 at 05:53
  • As data is rendering with high speed, you have to use Virtualization concept. Instead of Datagrid, use ListView as it has capabilities of virtualization. You can find a good discussion on http://stackoverflow.com/questions/14456075/how-to-enable-ui-virtualization-in-standard-wpf-listview – Naresh Ravlani Apr 13 '17 at 05:55
  • I have edited and added the code please have a look. @janonimus – shravan Apr 13 '17 at 06:46
  • @NareshRavlani In datagrid there is a provision of VirtualizingStackPanel.VirtualizationMode I have set it to "Recycling" and VirtualizingStackPanel.IsVirtualizing is "true". – shravan Apr 13 '17 at 06:49
  • 1
    Updating the UI with that frequency makes no sense. It wouldn't even be perceivable. You should instead queue your data and update the DataGrid 20 or 30 times a second. – Clemens Apr 13 '17 at 07:07
  • @Clemens I will consider your suggestion and make necessary changes in my implementation and get back. – shravan Apr 13 '17 at 08:08

0 Answers0