0

Windows Phone 7 응용 프로그램에서 작동 중이고 와이드 타일과 같은 Windows Phone 8의 기능을 구현하려고합니다. 나는 리플렉션을 사용하여 그것을 달성했지만 주기적 작업을 위해 ScheduledAgent를 사용하여 타일을 업데이트하고자 할 때 타일이 생성되지 않습니다.Windows Phone에서 타일을 업데이트하는 데 ScheduledTaskAgent가 작동하지 않습니다.

예정된 제 내가 주기적 작업

private void RegisterAgent() 
    { 
     string taskName = "MyTask"; 
     try 
     { 

      if (ScheduledActionService.Find(taskName) != null) 
      { 
       //if the agent exists, remove and then add it to ensure 
       //the agent's schedule is updated to avoid expiration 
       ScheduledActionService.Remove(taskName); 
      } 

      PeriodicTask periodicTask = new PeriodicTask(taskName); 
      periodicTask.Description = "Random Quote Update On Tile"; 
      ScheduledActionService.Add(periodicTask); 

     } 
     catch (InvalidOperationException exception) 
     { 
      MessageBox.Show(exception.Message); 
     } 
     catch (SchedulerServiceException schedulerException) 
     { 
      MessageBox.Show(schedulerException.Message); 
     } 
    } 

를 등록하는 등록 에이전트 방법했다

public class CreateTileForWindowsPhone 
{ 
    private static Version TargetedVersion = new Version(7, 10, 8858); 
    public static bool IsTargetedVersion { get { return Environment.OSVersion.Version >= TargetedVersion; } } 

    public static void CreateWideTile() 
    { 
     if (IsTargetedVersion) 
     { 
      try 
      { 
       // Get the new FlipTileData type. 
       Type flipTileDataType = Type.GetType("Microsoft.Phone.Shell.FlipTileData, Microsoft.Phone"); 
       // Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates. 

       Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone"); 
       // Loop through any existing Tiles that are pinned to Start. 

       QuotesCollection aq = new QuotesCollection(); 
       Random rand = new Random(); 
       int randNum = rand.Next(0, 163); 

       //String wideBackStr = "Dont be the same, Be Better."; 
       String wideBackStr = aq.quotes[randNum]; 

       foreach (var tileToUpdate in ShellTile.ActiveTiles) 
       { 
        // Get the constructor for the new FlipTileData class and assign it to our variable to hold the Tile properties. 
        var UpdateTileData = flipTileDataType.GetConstructor(new Type[] { }).Invoke(null); 

        // Set the properties. 
        SetProperty(UpdateTileData, "WideBackgroundImage", new Uri("/images/QuottedWideTile.png", UriKind.Relative)); 
        SetProperty(UpdateTileData, "WideBackContent", wideBackStr); 
        // Invoke the new version of ShellTile.Update. 
        shellTileType.GetMethod("Update").Invoke(tileToUpdate, new Object[] { UpdateTileData }); 
        break; 
       } 
      } 
      catch 
      { 
       MessageBox.Show("Tile Error Caught"); 
      } 
     } 
    } 

    private static void SetProperty(object instance, string name, object value) 
    { 
     var setMethod = instance.GetType().GetProperty(name).GetSetMethod(); 
     setMethod.Invoke(instance, new object[] { value }); 
    } 
} 

코드를 이용하여 타일을 생성

protected override void OnInvoke(ScheduledTask task) 
{ 
    //TODO: Add code to perform your task in background 
    if (task is PeriodicTask) 
    { 
     //Update the tile using Scheduled Task 
     CreateTileForWindowsPhone.CreateWideTile(); 
    } 
    NotifyComplete(); 
} 

같은 코드 보이는 OnInvoke 앱에서 레지스터를 호출하면

private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
     RegisterAgent(); 
    } 

하지만 앱을 실행할 때 와이드 타일이 생성되지 않습니다. 예정된 상담원을 사용하여 타일을 업데이트하기 전에 와이드 타일 만들기가 사용되었습니다. 나는 응용 프로그램 시작시 해당 함수를 호출하여 와이드 타일을 만드는 데 사용되었습니다.

private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
     CreateTileForWindowsPhone.CreateWideTile(); 
    } 

타일이 생성되지 않습니다. 내가 뭐 잘못하고 있니?

+0

왜 WP7을 타겟팅하고 리플렉션을해야합니까? WP8로 업그레이드하고 타일을 업데이트 해 보셨습니까? – robwirving

+0

현재 메신저는 vs2010의 Wp7에서 작업 중입니다. 그래서 저는 반사를 사용하여 타일을 만듭니다. 방금 ​​"잘못된 크로스 스레드 오류"를 발견했습니다. 어떤 제안? –

+0

UI 스레드에서 일부 코드를 실행해야하는 것처럼 들립니다. Dispatcher RunAsync 사용 – robwirving

답변

0
Deployment.Current.Dispatcher.BeginInvoke(
    CreateTileForWindowsPhone.CreateWideTile);