using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using Windows.Devices.Bluetooth.Advertisement;

internal static class ScanBle
{
    private static int Main()
    {
        var seen = new ConcurrentDictionary<ulong, string>();
        var watcher = new BluetoothLEAdvertisementWatcher
        {
            ScanningMode = BluetoothLEScanningMode.Active
        };

        watcher.Received += (sender, args) =>
        {
            var name = args.Advertisement.LocalName;
            if (!string.IsNullOrWhiteSpace(name))
                seen[args.BluetoothAddress] = name;
        };

        watcher.Start();
        Thread.Sleep(TimeSpan.FromSeconds(12));
        watcher.Stop();

        foreach (var item in seen.OrderBy(item => item.Value).ThenBy(item => item.Key))
            Console.WriteLine("{0:X12} {1}", item.Key, item.Value);
        return 0;
    }
}
