windows 8应用程序每分钟更新一次磁贴图像

本文关键字:一次 图像 应用程序 每分钟 更新 windows | 更新日期: 2023-09-27 18:25:15

嗨,我需要每分钟更新我的互动程序的图像,但我找不到任何解决方案。我看过这个,但我很难把它发挥作用。

瓦片中的图像从网络加载两次,但之后不会再加载;如何每分钟更新互动程序中的图像?

例如:在这里,我的互动程序和数字是网络服务器上的图像,我需要每分钟用任何新图像刷新此图像。

 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)
            {
            }
        }
    }

windows 8应用程序每分钟更新一次磁贴图像

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

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

如果你使用随机查询字符串,比如

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

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

看看我关于通知图像处理的博客文章,特别是"云中的图像"一节,了解更多上下文。