Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. await can't find GetAwaitor method

await can't find GetAwaitor method

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpvisual-studiohelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    __John_
    wrote on last edited by
    #1

    The error...

    Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation' have a suitable GetAwaiter method. Are you missing a using directive for 'System'? C:\Users\jo\Documents\Visual Studio 2013\Projects\Btle01\Btle01\Form1.cs 29 46 Btle01

    My code...

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    using System.Threading.Tasks;
    using Windows.Devices.Bluetooth;
    using Windows.Devices.Enumeration;
    using Windows.Foundation;
    using Windows.System;

    namespace Btle01
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

        private void OnFormLoad(object sender, EventArgs e)
        {
        }
    
        private async Task GetDevs()
        {
            foreach (DeviceInformation di in await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()))
            {
                BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(di.Id);
                listView1.Items.Add(bleDevice.Name);
            }
        }
    
    }
    

    }

    List of project references...

    False
    ..\..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll

    ..\\..\\..\\..\\..\\..\\..\\Windows\\System32\\WinMetadata\\Windows.Devices.winmd
    
    N 1 Reply Last reply
    0
    • _ __John_

      The error...

      Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation' have a suitable GetAwaiter method. Are you missing a using directive for 'System'? C:\Users\jo\Documents\Visual Studio 2013\Projects\Btle01\Btle01\Form1.cs 29 46 Btle01

      My code...

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Text;
      using System.Windows.Forms;
      using System.Threading;
      using System.Threading.Tasks;
      using Windows.Devices.Bluetooth;
      using Windows.Devices.Enumeration;
      using Windows.Foundation;
      using Windows.System;

      namespace Btle01
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

          private void OnFormLoad(object sender, EventArgs e)
          {
          }
      
          private async Task GetDevs()
          {
              foreach (DeviceInformation di in await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()))
              {
                  BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(di.Id);
                  listView1.Items.Add(bleDevice.Name);
              }
          }
      
      }
      

      }

      List of project references...

      False
      ..\..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll

      ..\\..\\..\\..\\..\\..\\..\\Windows\\System32\\WinMetadata\\Windows.Devices.winmd
      
      N Offline
      N Offline
      Nathan Minier
      wrote on last edited by
      #2

      I see that this has been gathering dust for a few days, so I'm sorry if I'm too late to the party to help you.

      foreach (DeviceInformation di in await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()))

      This is a problem. basically you're attempting to iterate a collection of promises, but without a custom iterator the compiler has no idea what to do with those promises. The easy fix is to move the asynch resolution to a variable and await it, like so:

      ...
      // allow synchronization before iteration
      var myArray = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());

      foreach(DeviceInformation di in myArray)
      ...

      Alternatively, you can abuse some of the async functionality in LINQ (I haven't validated this block, so it might need tweaking):

      var result = await Task.WhenAll(Windows.Devices.Enumeration.DeviceInformation
      .FindAllAsync(BluetoothLEDevice.GetDeviceSelector())
      .Select(async x => await BluetoothLEDevice.FromIdAsync(x.Id)).ToArray());

      result.Select(x => listView1.Items.Add(x.Name));

      There are plenty of other ways to skin this cat, should you happen to like cat skins. Both of these approaches should work, though.

      _ 1 Reply Last reply
      0
      • N Nathan Minier

        I see that this has been gathering dust for a few days, so I'm sorry if I'm too late to the party to help you.

        foreach (DeviceInformation di in await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()))

        This is a problem. basically you're attempting to iterate a collection of promises, but without a custom iterator the compiler has no idea what to do with those promises. The easy fix is to move the asynch resolution to a variable and await it, like so:

        ...
        // allow synchronization before iteration
        var myArray = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());

        foreach(DeviceInformation di in myArray)
        ...

        Alternatively, you can abuse some of the async functionality in LINQ (I haven't validated this block, so it might need tweaking):

        var result = await Task.WhenAll(Windows.Devices.Enumeration.DeviceInformation
        .FindAllAsync(BluetoothLEDevice.GetDeviceSelector())
        .Select(async x => await BluetoothLEDevice.FromIdAsync(x.Id)).ToArray());

        result.Select(x => listView1.Items.Add(x.Name));

        There are plenty of other ways to skin this cat, should you happen to like cat skins. Both of these approaches should work, though.

        _ Offline
        _ Offline
        __John_
        wrote on last edited by
        #3

        Hi Nathan, thanks for the response, I will try your suggestions. - John

        “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups