我使用Xamarin.Android中的AltBeacon库每30秒检测一次信标 .

30秒逻辑的循环以30秒后再次调用的方法递归地发生 .

我的 BeaconClass 中有以下部分代码:

public void DetectAvailableBeacons()
    {
        _monitorNotifier = new MonitorNotifier();

        _rangeNotifier = new RangeNotifier();

        _tagRegion = new Region("NewRegion",null, null, null);

        _beaconManager.Bind(this);

        _rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegionComplete;

    }
    public static void RangingBeaconsInRegionComplete(object sender, RangeEventArgs e)
    {
            if (e.Beacons.Count > 0)
            {
                foreach (var b in e.Beacons)
                {
                    detectedBeacons?.Add(new BeaconDetected
                            (b.Id1.ToString().ToUpper(), b.Id2.ToString(), b.Id3.ToString(), string.Concat(b.Id2, b.Id3), null) );
                }                    
            }
    }

    public void StartTracking()
    {
        detectedBeacons.Clear(); // clear the previous list of beacons scanned
        DetectAvailableBeacons(); // perform a new detection

    }

    public ObservableCollection<DetectedBeacon> GetAvailableBeaconsService()
    {
       return detectedBeacons;
    }

我的UI上有 buttonlistview . 部分代码如下所示在Beacons.xaml.cs中

public async void Button_clicked(object sender, EventArgs e)
{
     PopulateBeaconsOnListView(); 
     await Task.Delay(3000);
     PopulateBeaconsOnListView(); 
}

public void PopulateBeaconsOnListView() {
              // I call the method StartTracking() 
    BeaconClass bea = new BeaconClass();
    bea .StartTracking();
    foundBeacons = bea.GetAvailableBeacons()
    listview.ItemsSource = foundBeacons();
}

我的问题是我是否在30秒后有效地进行了扫描周期?监听器是否继续运行/扫描?这是因为检测到的信标会在每30秒后显示在我的列表视图中 . 在效率方面,这是正确的做法吗?

请指教 .