Jerky scrollbar and async usage

4 posts, 1 answers
  1. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 15 Aug 2013 Link to this post

    1. I had found several threads about that, but either description was not complete, or answer was a bit blurry. Anyway, i'm also facing this problem. While having a list of several dozen items, it scrolls perfectly, but scrollbar is moving jerky indeed.

    Sample (not mine, just was testing it, and found problem there), where you can see jerking of scrollbar (i got it on Lumia 920 device):
    https://skydrive.live.com/redir.aspx?cid=0c89662af4d9c150&resid=C89662AF4D9C150!335&parid=C89662AF4D9C150!334


    2. I hate those bloody callbacks, so i switched to Bcl library. Now, i'm trying to fill Listbox with own data, but somehow, page is always waiting for async call to be finished.

    So, xaml: 

    <telerikPrimitives:RadDataBoundListBox
                    Grid.Row="1"
                    EmptyContent=""
                    DataVirtualizationMode="Automatic"
                    CacheMode="BitmapCache"
                    ItemTemplate="{StaticResource ProductsListViewerItemTemplate}"
                    ItemsSource="{Binding VirtualDataCollection}"
                    >

    ViewModel:

    VirtualDataCollection = new VirtualizingDataCollection(Constants.PAGE_SIZE, Constants.PAGE_SIZE);
    VirtualDataCollection.ItemsLoading += VirtualDataCollectionOnItemsLoading;

    async private void VirtualDataCollectionOnItemsLoading(object sender, VirtualizingDataCollectionItemsLoadingEventArgs e)
            {
                var answer = await _dataService.RequestServerAsync(SelectedIndex, e.StartIndex, e.Count);
                if (answer.Status == AnswerDataServiceStatus.Ok) // Added breakpoint here, page is freezing and waiting for this line
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() => 
                        VirtualDataCollection.LoadItems(e.StartIndex, answer.Collection));
                }
            }


    DataService:

    public async Task<ProductAnswer> RequestServerAsync(string categoryId, int startIndex, int pagesize)
            {
                Thread.Sleep(5000);

                return new ProductAnswer
                    {
                        Status = AnswerDataServiceStatus.Ok,
                        Collection =
                            new List<ProductItem> {new ProductItem {name = "One"}, new ProductItem {name = "Two"}}
                    };

            }
  2. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 16 Aug 2013 Link to this post

    Actually, i solved second problem by moving async to background thread, but i'm not sure, if its a good idea and supported by design.

    private void VirtualDataCollectionOnItemsLoading(object sender, VirtualizingDataCollectionItemsLoadingEventArgs e)
            {
                ThreadPool.QueueUserWorkItem(async o =>
                    {
                        var answer = await _dataService.RequestServerAsync(SelectedIndex, e.StartIndex, e.Count);
                        if (answer.Status == AnswerDataServiceStatus.Ok)
                        {
                            DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                                                  VirtualDataCollection.LoadItems(e.StartIndex,
                                                                                                  answer.Collection));
                        }
                    });
            }
  3. DevCraft banner
  4. Answer
    Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 19 Aug 2013 Link to this post

    Hello Vitalii,

    Thanks for writing.

    1. This behavior is resulting from our current implementation of a UI virtualization mechanism. We have plans to optimize this behavior in the near future.

    2. It might be so that the async in the data service provider you are using is not implemented by using background workers and thus the call is happening on the UI thread which leads to page freeze. Moving it to a background worker on your side is a good solution.

    Let us know if you have additional questions.

    Regards,
    Deyan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 19 Aug 2013 Link to this post

    Thanks, good to hear.
Back to Top