Вопрос

Hi, I need update the image of my tile every minute, but I cannot find any solution. I've looked at this but I'm having trouble getting it to work.

Images in tiles are loaded from web twice but not again after that; How can I update the images in my tile every minute?

For example: Here, my tile and numbers are images on a web server and I need to refresh this image every minute with any new images.

 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)
            {
            }
        }
    }
Это было полезно?

Решение

I'm presuming here that you are seeing the Debug.WriteLine output, and you've confirmed you're not swallowing the exception in your empty catch.

Have you tried running Fiddler? Since you're requesting the same image over and over, I wonder if it's being served out of a local cache (though why you'd see the right one twice is a little mysterious).

If you tack on a random query string, say

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

that might fool the cache (and be a quick test to see if that may be the issue). If it is though(and it's not something AFAIK you have control over), a better option would be to set response headers on the image retrieval (via a service) that will set an appropriate no-cache header; otherwise, you're filling the caches with never-to-be-reused images.

Take a look at my blog post on image handling with notifications, particularly the section "Images in the Cloud" for a little more context.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top