c# - HRESULT 异常:0x80640012
问题描述
我正在尝试收听 connectionRequested 侦听器,
private WiFiDirectConnectionListener _listener;
...
_listener.ConnectionRequested += ConnectionRequestedAsync;
这是侦听器回调,
private async void ConnectionRequestedAsync(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs args)
{
WiFiDirectConnectionRequest request = args.GetConnectionRequest();
if (request != null)
{
try
{
WiFiDirectDevice _device = await WiFiDirectDevice.FromIdAsync(request.DeviceInformation.Id);
...
}
catch (Exception e)
{
Debug.WriteLine(string.Format("Exception::\"{0}\"", e.Message));
}
}
}
在日志中发现异常(对于 call WiFiDirectDevice.FromIdAsync
),
异常::“来自 HRESULT 的异常:0x80640012”
任何想法可能是什么原因?
解决方案
下面的代码对我有用,
try
{
// IMPORTANT: FromIdAsync needs to be called from the UI thread
if (Application.Current.Dispatcher.CheckAccess())
{
_wfdDevice = await WiFiDirectDevice.FromIdAsync(deviceID);
}
else
{
await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(async () =>
{
_wfdDevice = await WiFiDirectDevice.FromIdAsync(deviceID);
}));
}
}
catch (Exception ex)
{
Logger.E($"Exception in FromIdAsync: {ex.Message}, StackTrace: {ex.StackTrace}\n\r");
}
推荐阅读
- flutter - 当它的孩子被定义为类成员时,GridView 不会重绘
- mysql - 如何加密 mysql 中的 TEXT 字段列
- c - 放一个 0 和一个 是什么意思。前 %
- centos7 - 为什么我的 vps 服务器响应时间过长?
- flutter - 我希望计时器在颤振中使用后过期
- r - 基于R中最低温度的多站冷波事件计算
- python - 检查字符串是否由子字符串列表组成
- python-3.x - 使用 Jenkins 声明性管道脚本读取 csv 并打印匹配的文本
- javascript - 如何模拟鼠标向上事件结构js
- javascript - 如何解决javascript中的“无法读取未定义的属性'包含'”