2013-07-29 62 views
0

嗨,我需要每分鐘更新我的瓷磚的圖像,但我找不到任何解決方案。我已經看過this,但我無法正常工作。更新瓷磚圖像每分鐘Windows 8應用程序

瓷磚中的圖像從網上加載兩次,但之後不再;我怎樣才能每分鐘更新瓷磚中的圖像?

例如: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) 
      { 
      } 
     } 
    } 
+0

你確定你不是剛剛脫離你的try {} catch {}塊? – Izzy

回答

1

我假定在這裏,你所看到的Debug.WriteLine輸出,和您確認你沒有吞嚥異常在空catch

您是否嘗試過運行Fiddler?由於您一遍又一遍地請求相同的圖像,我不知道它是否從本地緩存中提供服務(但爲什麼你會看到正確的兩次有點神祕)。

如果你釘在一個隨機的查詢字符串,說

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

可能騙過緩存(和是一個快速測試,看看是否能可能是問題)。如果它是(但它不是你可以控制的AFAIK),更好的選擇是在圖像檢索(通過服務)上設置響應頭,該頭將設置適當的no-cache頭;否則,您將使用不可重複使用的圖像填充緩存。

看一看my blog post on image handling with notifications,特別是「雲中的圖像」一節中的更多內容。