【问题标题】:adding tile with AddTileAsync() causes exception使用 AddTileAsync() 添加图块会导致异常
【发布时间】:2023-03-25 07:35:01
【问题描述】:

我尝试将新磁贴从 Windows Phone 8.1(SDK 从 2015 年 7 月开始)添加到 Microsoft Band,

但是当我添加新磁贴时(通过下面包含的代码),我得到了允许第三方磁贴的对话框。在此对话框与 Band 同步后,在我收到此异常后:

{Microsoft.Band.BandIOException: 无法连接到目标频段。 ---> System.AggregateException:发生一个或多个错误。 ---> System.Exception: 每个套接字地址只能使用一次 (协议/网络地址/端口)通常是允许的。只有一种用法 每个套接字地址(协议/网络地址/端口)的通常是 允许。 --- 内部异常堆栈跟踪结束 --- 在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) 在 System.Threading.Tasks.Task.Wait(Int32 毫秒超时, CancellationToken 取消令牌)在 System.Threading.Tasks.Task.Wait() 在 Microsoft.Band.Store.BluetoothTransportBase.Connect(RfcommDeviceService service, UInt16 maxConnectAttempts) --- 内部异常结束 堆栈跟踪 --- ...

带代码:

 using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
 {
     try
     {
         IEnumerable<BandTile> tiles = await bandClient.TileManager.GetTilesAsync();
         foreach (var t in tiles)
         {
             if (await bandClient.TileManager.RemoveTileAsync(t))
             {
             }
          }
          var remaining = await bandClient.TileManager.GetRemainingTileCapacityAsync();
          if (remaining == 0)
          {
              return;
          }

          Guid tileGuid = Guid.NewGuid();
          BandTile tile = new BandTile(tileGuid)
          {
              Name = "BandTestTile",
              SmallIcon = smallIcon,
              TileIcon = tileIcon,
          };
          await bandClient.TileManager.AddTileAsync(tile);
          await bandClient.NotificationManager.ShowDialogAsync(tileGuid, "Hello", "Hello world!");

           Guid messagesPageGuid = Guid.NewGuid();
           PageData pageContent = new PageData(
                 messagesPageGuid,
                 0,
                 new WrappedTextBlockData(
                 (Int16)TileMessagesLayoutElementId.Message1,
                 "This is the text of the first message"),
                 new WrappedTextBlockData(
                 (Int16)TileMessagesLayoutElementId.Message2,
                 "This is the text of the second message")
                );

            await bandClient.TileManager.SetPagesAsync(tileGuid, pageContent);
      }
      catch (BandException ex)
      {
      }
  }

你有什么想法,有什么问题吗?

【问题讨论】:

    标签: c# microsoft-band


    【解决方案1】:

    该异常通常意味着有多个应用程序(或给定应用程序中的多个线程)试图同时与 Band 通信。在任何给定时间只允许单个 IBandClient“连接”。

    • 确保没有其他应用程序(例如后台任务)正在使用 Band
    • 确保在执行上面显示的代码之前,正确处理应用程序中对 IBandClient 的所有使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多