Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

UI does not responds/updates while rapid view model data updates in thread

$
0
0

Hi,
I'm working in a Xamarin Forms app that must display rapid changing numbers on the screen. For the sake of explaining let's say I have four labels on the screen which display multiple values that change rapidly. I'm using a view model and data binding to update these labels. To update values at the view model I initially used a device timer as follows. This works, but when running on a device it is very slow:

Device.StartTimer(new TimeSpan(0, 0, 0, 0, 250), () => 
{
    // View model updates here
}

I'm trying to perform the updates using a separate thread, but can't get the UI to respond. I've tried using an async Task also with the same results. Here is something I tried without good results:

private void StartUpdates()
{
    new System.Threading.Thread(new System.Threading.ThreadStart(() => 
    {
        Device.BeginInvokeOnMainThread(() => 
          {
              LoopTest();
          });
    })).Start();
}

private void LoopTest()
{
    while (condition)
    {
        Application.Current.MainPage.BatchBegin();
        // View model updates here
        Application.Current.MainPage.BatchCommit();
        // Short delay of few milliseconds may be needed here, i.e. 200
    }
}

Is there a way to create a separate thread to rapidly update my view model and have the UI update as well (or at intervals)?
Basically, I can't seem to find a way to rapidly update the data and refresh the UI...

Thanks!
Ignacio


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>