每次用户打开我的应用程序时,该应用程序都需要检查是否需要向 Windows Azure 上传/下载数据。但是,如果用户没有互联网连接,应用程序将在系统托盘中显示上次更新时间。该应用程序从 SQLite 获取最后更新时间,不需要使用 wait 方法来执行此操作。那么,我怎样才能让系统托盘中的文本持续几秒钟,然后它就会淡出。
这是我的代码
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();
}
}
}
}
}
谢谢
最佳答案
没有内置支持在有限的时间内显示进度条,因此您可能需要为此使用计时器:
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();
关于c# - 如何在不使用等待的情况下在系统托盘中显示进度指示器几秒钟 [Windows Phone 8],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22353985/