Issue
I am switching between pages on my Xamarin app. From a list that updates every 10 seconds, to another form that checks a boolean every 250ms. Both run a Device.StartTimer, but shouldn't overlap.
This is the start timer on the List Form:
protected override void OnAppearing()
{
base.OnAppearing();
vm.cmdReload.Execute(null);
//...
blnTimerActive = true;
startTimer();
}
private void startTimer()
{
Device.StartTimer(System.TimeSpan.FromSeconds(10), () =>
{
if (!blnTimerActive)
return false;
UpdateUserDataAsync();
return true;
}); // This is where it breaks, I think..
}
protected override void OnDisappearing()
{
base.OnDisappearing();
blnTimerActive = false;
}
Every time I try to run, it shows an error saying "No compatible code running on the thread" and "Object reference not set to an instance of an object." Error message
This happens after I am on the next form and this one is "disappeared" I'm not sure why this timer is still running. Any help is much appreciated! Let me know if I can make this question any easier to understand.
Solution
I figured it out by double checking the output. It crashed in my code, but somehow didn't show where the break happened. I checked the output and it showed exactly where it was.
If this is happening to you, check your output carefully. It should say what line number there was an error in, add a try catch, and step through. You should find your error easily that way.
thanks everyone for the help!
Answered By - Scott Uphus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.