C# 即使应用程序位于前台,磁贴创建也会失败

C# 即使应用程序位于前台,磁贴创建也会失败,c#,windows-phone-7,windows-phone-8,C#,Windows Phone 7,Windows Phone 8,我正在尝试从应用程序中的页面创建一个互动程序,效果很好 ShellTile.Create(new Uri(uri, UriKind.Relative), tileData, true); 如果我对应用程序进行逻辑删除,然后将应用程序放回前台,然后尝试创建互动程序,我会收到以下错误消息: System.InvalidOperationException: Tiles can only be created when the application is in the foreground

我正在尝试从应用程序中的页面创建一个互动程序,效果很好

ShellTile.Create(new Uri(uri, UriKind.Relative), tileData, true);
如果我对应用程序进行逻辑删除,然后将应用程序放回前台,然后尝试创建互动程序,我会收到以下错误消息:

System.InvalidOperationException: Tiles can only be created when the application is in the foreground
   at Microsoft.Phone.Shell.SafeNativeMethods.ThrowExceptionFromHResult(Int32 hr, Exception defaultException)
   at Microsoft.Phone.Shell.ShellTile.Create(Uri navigationUri, ShellTileData initialData, Boolean supportsWideTile)
这只会发生在相当低端的设备上

你知道怎么解决这个问题吗

编辑: 这是调用平铺创建函数的函数

    private void OnPinToStartButtonClicked(object sender, RoutedEventArgs e)
    {
        if (MyRouteTileHelper.FindCommuteTile() == null)
        {
            LiveTileHelper.CreateEmptyTile();
        }
    }
和xaml:

   <Button x:Name="PinToStartButton" Click="OnPinToStartButtonClicked" />

在创建互动程序之前,只需检查应用程序是否已创建。如果它已经创建,那么您将得到一个错误。我想在你的情况下,这个错误可能被掩盖了

Dispatcher.BeginInvoke(()=>{
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("any string of uri or search for unique prop"));
if (TileToFind == null)
{
   ShellTile.Create(Navi_Uri , tileData, true);
   MessageBox.Show("Tile is created.");
}
else
{
   TileToFind.Update(tileData);
   MessageBox.Show("Tile is updated");
}});
编辑 我认为当代码在单独的线程上执行时,会发生无效操作。你必须在UI线程上完成它。检查我编辑的代码部分


不管怎样,如果没有得到答案,请返回。

您要在哪里创建互动程序?它是在与导航相关的事件中,还是在对用户操作的直接响应中?点击按钮(因此它肯定是前景)在这种情况下,你有办法重现这个问题吗?在回答中,你提到了墓碑。您还提到通过单击按钮创建平铺。您正在尝试在应用程序事件处理程序中创建磁贴吗?您能提供创建磁贴的页面的方法事件吗?@MattLacey是的,低端设备,墓碑,然后单击创建磁贴的按钮hey@max,谢谢您的帮助。我已经在检查瓷砖是否存在。有关缺少的调用函数,请参见编辑应答