【问题标题】:System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task): HRESULT: 0x80640012System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务):HRESULT:0x80640012
【发布时间】:2021-06-14 00:33:10
【问题描述】:
    private static async void OnConnectionRequestedAsync(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs eventArgs)
    {
        WiFiDirectConnectionRequest connectionRequest = eventArgs.GetConnectionRequest();
        string deviceName = connectionRequest.DeviceInformation.Name;
        string deviceID = connectionRequest.DeviceInformation.Id;

        DeviceInformation devinfo = connectionRequest.DeviceInformation;
        bool isPaired = (devinfo.Pairing?.IsPaired == true) ||
                        (await IsAepPairedAsync(deviceID));
        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); // Exception Line
                }));
            }

        }
        catch (Exception ex)
        {
            Logger.Data($"Exception in FromIdAsync: {ex.Message}, StackTrace: {ex.StackTrace}\n\r");
        }
    }

仍然出现以下错误:

System.Exception
  HResult=0x80640012
  Message=Exception from HRESULT: 0x80640012
  Source=mscorlib
  StackTrace:
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at TestApp.WifiDirectPublisher.<>c__DisplayClass8_0.<<OnConnectionRequestedAsync>b__0>d.MoveNext() in D:\git\TestApp\WifiDirectPublisher.cs:line 75
    

我做错了什么?

【问题讨论】:

  • 你在开发 WPF 项目吗?
  • 是的@RoyLi-MSFT,我从 UWP 切换回 WPF 以避免弹出同意。
  • 顺便说一句,我正在尝试从 Android 设备连接到 Windows。
  • 我检查了错误代码,描述是客户端无法获取AEP的上下文,因为另一个客户端已经拥有。在您尝试连接之前,该设备是否已连接到其他应用?
  • @RoyLi-MSFT 不,这是唯一尝试连接的应用程序。没有其他 WD 连接。如何在请求之前以编程方式检查状态?

标签: c# wpf uwp wifi-direct


【解决方案1】:

添加以下代码:

client.Timeout = TimeSpan.FromSeconds(2000);

【讨论】:

  • 您能否更具体地了解代码的位置?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-23
  • 2018-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多