Reputation: 71
Every time when a user opens my app, the app needs to check that does it need to upload/download data to/from windows azure or not. However, if the user doesn't have internet connection, the app will show a last update time in System Tray. The app gets the last update time from SQLite which doesn't need to use await method to do it. So, how can I last the text in System tray for few seconds before it will be faded out.
This is my code
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if (SessionManagement.IsLoggedIn())
{
var userLastestPoopDataInSQLite = new SQLiteFunctions().GetUserPoopData(SessionManagement.GetEmail());
if (userLastestPoopDataInSQLite.Count != 0)
{
userLastestpoopRecordInSqlite = userLastestPoopDataInSQLite.Last();
if (!NetworkInterface.GetIsNetworkAvailable())
{
SystemTray.ProgressIndicator = new ProgressIndicator();
SystemTray.ProgressIndicator.Text = GetLastUpdatedTimeInText(userLastestpoopRecordInSqlite.Date_Time);
SystemTray.ProgressIndicator.IsVisible = true;
}
else
{
isUpdateNeeded = DateTime.Compare(userLastestpoopRecordInSqlite.Date_Time, userLastestPoopRecordInAzure.Date_Time);
Debug.WriteLine("Lastest time in Sqlite" + userLastestpoopRecordInSqlite.Date_Time);
Debug.WriteLine("Lastest time in azure" + userLastestPoopRecordInAzure.Date_Time);
Debug.WriteLine(isUpdateNeeded);
if (isUpdateNeeded == 0)
{
SystemTray.ProgressIndicator = new ProgressIndicator();
SystemTray.ProgressIndicator.Text = "Data is up-to-date";
SystemTray.ProgressIndicator.IsVisible = true;
}
else
{
userLastestPoopDataInAzure = await new AzureFunctions().GetUserPoopDataInAzure(SessionManagement.GetEmail());
userLastestPoopRecordInAzure = userLastestPoopDataInAzure.Last();
StartSyncUserLastestData();
}
}
}
}
}
Thank you
Upvotes: 0
Views: 563
Reputation: 4359
There is no built in support for showing the progress bar a limited time, so you will probably need to use a timer for this:
SystemTray.ProgressIndicator = new ProgressIndicator();
SystemTray.ProgressIndicator.IsVisible = true;
SystemTray.ProgressIndicator.Text = "Data is up-to-date";
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(2000);
timer.Tick += (sender, args) =>
{
SystemTray.ProgressIndicator.IsVisible = false;
timer.Stop();
};
timer.Start();
Upvotes: 3