c# - 如何在不使用等待的情况下在系统托盘中显示进度指示器几秒钟 [Windows Phone 8]

标签 c# azure windows-phone-8

每次用户打开我的应用程序时,该应用程序都需要检查是否需要向 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/

相关文章:

azure - 从 Azure 存储中删除 "subpath"

azure - MVC/Azure 中 "like"搜索的最佳部署是什么

c# - Windows Phone 开发 - IsolatedStorage

c# - 炼金术网络套接字 : Can't host server on Azure

c# - 每当修改一个字段时修改另一个字段

c# - 关于 C# 4.0 泛型协变的问题

javascript - 使复选框成为一组单选按钮

Azure Function 在启动时运行代码

c# - 如何修复错误 : Cannot call the requested method (GetBasicPropertiesAsync). 之前对此方法的调用正在挂起

windows-phone-7 - Windows Phone 8 平台上的 GPS 错误行为