I am new to Windows Phone Dev, and am migrating my WP8 SilverLight app to WP8.1 WinRT. Below is my working code on my ViewModel for WP8 which is not working for the Store app.
Logic behind the code is to update the Xaml txtBox values on UI thread every second which is done inside the UpdateTicker() method.
WP8 Working Code:
Task.Run(async () =>
{
while (true)
{
await Task.Delay(1000);
Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
{
UpdateTicker(); // this method gets called every second
}), null);
}
});
After a lot of search on, MSDN and SO, this where i got to, Below code compile fine for wp8.1 winRT but still does not work - when put a break-point, the debugger reach to the UpdateTicker() step only once, whereas UpdateTicker
method should have called every second, (which is what happening for the 1st block of code)
WP8.1 WinRT Code:
Task.Run(async delegate
{
while (true)
{
await Task.Delay(1000);
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UpdateTicker(); // this method does not get called every second
});
}
});
Any guidance on using Async Task and Dispatcher.BeginInvoke(Or likewise) together from ViewModel for wp8.1 env is appreciated.