【问题标题】:Update tile image every minute windows 8 app每分钟更新平铺图像 Windows 8 应用程序
【发布时间】:2013-07-31 12:22:32
【问题描述】:

您好,我需要每分钟更新一次磁贴的图像,但我找不到任何解决方案。我查看了this,但无法让它工作。

图块中的图像从网络加载两次,但之后不再加载;如何每分钟更新磁贴中的图像?

例如:Here,我的磁贴和数字是网络服务器上的图像,我需要每分钟用任何新图像刷新此图像。

 public static void CreateSchedule()
    {




        var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
        var plannedUpdated = tileUpdater.GetScheduledTileNotifications();


        DateTime now = DateTime.Now;
        DateTime planTill = now.AddHours(4);

        string src1 = "http://mysite/squareLogo128.png";

        DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1);
        if (plannedUpdated.Count > 0)
            updateTime = plannedUpdated.Select(x => x.DeliveryTime.DateTime).Union(new [] { updateTime }).Max();



        string xml = "<tile>"
                         + "<visual>"
                         + "<binding template='TileWideImageAndText01'>"
                         + "<text id='1'>This tile notification uses web images</text>"
                         + "<image id='1' src='" + src1 + "' alt='Web image'/>"
                         + "</binding>"
                         + "<binding template='TileSquareImage'>"
                         + "<image id='1' src='" + src1 + "' alt='Web image'/>"
                         + "</binding>"
                         + "</visual>"
                         + "</tile>";

        XmlDocument documentNow = new XmlDocument();
        documentNow.LoadXml(xml);

        tileUpdater.Update(new TileNotification(documentNow) { ExpirationTime = now.AddMinutes(1) });
        for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddMinutes(1))
        {
            Debug.WriteLine(startPlanning);
            Debug.WriteLine(planTill);

            try
            {
                string src2 = "http://mysite/squareLogo128.png";
                string xml2 = "<tile>"
                        + "<visual>"
                        + "<binding template='TileWideImageAndText01'>"
                        + "<text id='1'>This tile notification uses web images</text>"
                        + "<image id='1' src='" + src2 + "' alt='Web image'/>"
                        + "</binding>"
                        + "<binding template='TileSquareImage'>"
                        + "<image id='1' src='" + src2 + "' alt='Web image'/>"
                        + "</binding>"
                        + "</visual>"
                        + "</tile>";

                XmlDocument document = new XmlDocument();
                document.LoadXml(xml2);

                ScheduledTileNotification scheduledNotification = new ScheduledTileNotification(document, new DateTimeOffset(startPlanning)) { ExpirationTime = startPlanning.AddMinutes(1) };
                tileUpdater.AddToSchedule(scheduledNotification);


            }
            catch (Exception e)
            {
            }
        }
    }

【问题讨论】:

  • 你确定你不只是掉出try{}catch{} 块吗?

标签: c# xml windows-8 windows-store-apps periodic-task


【解决方案1】:

我在这里假设您看到的是Debug.WriteLine 输出,并且您已经确认您没有在空的catch 中吞下异常。

您是否尝试过运行Fiddler?由于您一遍又一遍地请求相同的图像,我想知道它是否是从本地缓存中提供的(尽管为什么您会看到正确的图像两次有点神秘)。

如果你添加一个随机查询字符串,比如说

string src2 = "http://mysite/squareLogo128.png" + "?" + Guid.NewGuid().ToString();

这可能会欺骗缓存(并且可以快速测试一下这是否是问题所在)。如果是这样(并且它不是您可以控制的 AFAIK),更好的选择是在图像检索(通过服务)上设置响应标头,这将设置适当的无缓存标头;否则,您将使用永不重复使用的图像填充缓存。

查看my blog post on image handling with notifications,尤其是“云中的图像”部分了解更多上下文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-09
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    相关资源
    最近更新 更多