Hello
i have a list of sunset for each day for a period of a month like the date and time sunset
i would like to check every seconds if sunset time has arrived and then display a message.
i implemented using a timer but the message is not displayed
I forgot to mention it's in xamarin android When i launch the app let say 2 minutes before sunset string "before sunset" is displayed but when sunset time arrived the string doesn't change
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
DateTime da;
String sunsetmessage;
TimeSpan sunset, timeelapse;
RunOnUiThread(() =>
{
Boolean flagchange = false;
sunsetmessage = string.Empty;
da = DateTime.UtcNow;
sunsetitem = Getsunsettime();
sunset = new TimeSpan(sunsetitem.hour, sunsetitem.minute, 0);
timeelapse = sunset - new TimeSpan(da.Hour , da.Minute, 59);
if (timeelapse.TotalSeconds <= 0)
sunsetmessage = "after sunset";
else if (timeelapse.TotalSeconds == 0)
sunsetmessage = " sunset";
else
sunsetmessage = "before sunset";
announcement.text = sunsetmessage;
});
}
Thanks