locked
UI becomes mostly unresponsive RRS feed

  • Question

  • I have a really weird problem with Silverlight. Sometimes the UI becomes mostly unresponsive. What I mean mostly is that for example DataGrid scrollbars don't work at all. Columns cannot be moved/resized and grid cannot enter edit mode. GridSplitter don't work either. Buttons do work as well as comboboxes. When this happens all DataGrids and GridSplitters freeze. Not just one or two but all. When I refresh the page, the problem disappears. This happens very rarely and is hard to reproduce.

    Does anyone have any ideas why this could be happening? Or better yet, how to debug this when I get it reproduced? 

    Thursday, April 14, 2011 7:33 AM

Answers

  • Telos,

    It may be because of the huge amount of data placed in the datagrid in a single page (i.e. without paging)

    you can try by using the paging element using pagedcollectionview

     http://msdn.microsoft.com/en-us/library/dd833072(v=vs.95).aspx#Y4547

    Friday, April 15, 2011 4:39 PM
  • By "FIX the height" I meant, set the Height to a fixed value as opposed to having the layout engines figure out how high it should be.  I think you are doing the right thing now with regard to the height of the DataGrid.

    The problem was the StackPanel.  I think the default extent of Infinity is not what I expected when I started using it.  And I guess you didn't suspect it either.  But now we both know how those things work.

    Wednesday, April 20, 2011 1:54 PM

All replies

  • Two things come to mind.  First would be heavy activity on the UI thread.  For instance, charting thousands of points on a chart.  If the chart objects are created on the UI thread, you might have to wait until that has finished.

    Second thing that comes to mind is adding event handlers too many times.  For instance, let's say a handler is added in a scrolling event.  And the handler is never removed.  Then it is possible that a lot of scrolling could trigger more handlers to be created.  So potentially, there could be thousands of handlers on a given event.  And ALL of them would get called when appropriate.

    Thursday, April 14, 2011 7:46 AM
  • I've checked for the event handlers and I don't think it's that one. I'm not sure how can it be the UI thread either because the freezing doesn't go away. So even if UI thread work would freeze the UI, it would start responding once the work is over and it would affect every UI element, wouldn't it?

    In my case only the scrollbars, DataGrid columns and GridSplitters are affected. Buttons and ComboBoxes still work ok and I can select cells and rows from the DataGrid and that's what makes this weird.

    Any other ideas or tool suggestions for finding out more?

    Friday, April 15, 2011 12:16 AM
  • Telos,

    It may be because of the huge amount of data placed in the datagrid in a single page (i.e. without paging)

    you can try by using the paging element using pagedcollectionview

     http://msdn.microsoft.com/en-us/library/dd833072(v=vs.95).aspx#Y4547

    Friday, April 15, 2011 4:39 PM
  • FWIW, I think we've had 14,000 records in the datagrid and it didn't affect anything as far as performance.

    Saturday, April 16, 2011 9:07 AM
  • Hi,

    How's your issue going on?

    I'm agree with rakeshvasu39.

    Does your dataGrid has a larger data? If yes, I suggest you paging your DataGrid by using PagedCollectionView and DataPager control.

    please give that a try.

     

    Regards

    Tuesday, April 19, 2011 5:38 AM
  • Hi

    For what it's worth I have to say that I agree with the original comment - we frequently have datagrids that should fill the whole screen and have several hundred (even thousands) rows - and the scrolling and general performance is noticeably worse than any html equivalent.

    Using paging is not an option in most cases

    Tuesday, April 19, 2011 11:58 AM
  • ...

    For what it's worth I have to say that I agree with the original comment - we frequently have datagrids that should fill the whole screen and have several hundred (even thousands) rows - and the scrolling and general performance is noticeably worse than any html equivalent.

    ...

    Odd. As I said, we've done 14,000+ rows and the customers are in love with it because to get ONE page with the asp.net paged grid took about the same time as to get all 14,000 in a Silverlight datagrid.  And in Silverlight, they can filter, sort, scroll IMMEDIATELY on the client with no more server interaction.

    I wonder why your UI performance is so much worse than ours.

    Tuesday, April 19, 2011 12:44 PM
  • I'd sure be keen to find out. I suppose it could be one of many things eg

    • Computer - mine, XP x64 Xeon 4Gb
    • Use of converters to format cells and text
    • Fullscreen with hundreds of rows and twenty or so columns
    • Code uses MVVM and an ObservableCollection

    Anything on your side vastly different?

     

     

     

     

    Wednesday, April 20, 2011 7:26 AM
  • Well, you probably have more horsepower than I have. 

    I can't imagine the converters making any difference.  I think they only have to work for the number of cells visible and that should only be a couple of dozen I would think.  I probably only have a dozen columns, but that shouldn't make a difference either.  We use MVVM (which I love) and ObservableCollections.

    It just occurred to me what MIGHT be different.  If you have your DataGrid inside a STACKPANEL with Orientation="Vertical", then the effective height is INFINITE.  That means that ALL of the rows of the DataGrid would be drawn.  Even if you can't see them all on the screen.

    Make sure you have the DataGrid in a different type of container that has a fixed height like a Grid.  Or, FIX the height of the DataGrid.  You should be able to SEE the bottom of the DataGrid.  In this sort of case, there should only be a couple of dozen or so rows that need rendering at any time.  Otherwise, there may be a LOT of rendering required for all the rows.

    Not sure what you meant by "Fullscreen with hundreds of rows".  But we have thousands of rows, but only a relatively small number visible.

    Wednesday, April 20, 2011 7:47 AM
  • Thanks for the help. I've modified my code - it was indeed inside a StackPanel. That said any improvements are slight - for instance the scrolling still has a jerky feel. Wonder if it's something to do with our graphics card setup etc. The same grid rendered in straightforward html/css definitely scrolls more smoothly.

    Wednesday, April 20, 2011 9:20 AM
  • By the way what do you mean 'fix' the height of the datagrid - I've got it in a row of a grid with the rowdefinition rowheight set as *. This way it fills the page. Is this right?

    Wednesday, April 20, 2011 9:23 AM
  • By "FIX the height" I meant, set the Height to a fixed value as opposed to having the layout engines figure out how high it should be.  I think you are doing the right thing now with regard to the height of the DataGrid.

    The problem was the StackPanel.  I think the default extent of Infinity is not what I expected when I started using it.  And I guess you didn't suspect it either.  But now we both know how those things work.

    Wednesday, April 20, 2011 1:54 PM
  • Great discussion guys! I was on a holiday so I'm sorry I haven't been replying about this issue. Like I said, I have been on holiday and haven't been able to work on this problem for a while but the issue still remains. 

    I don't think it's about the height or amount of rows. I have been able to reproduce this issue with only 2 rows in a grid. And if it would be something related just to the grid, would it still cause the freezing of other scrollbars and gridsplitter? It can be something caused by the grid but the resulting problem is bigger than just the grid. 

    I'm about to try the fixed height to see if I can still reproduce it. 

    Tuesday, April 26, 2011 4:01 AM