# Background audio device refreshing

**URL:** <https://forum.juce.com/t/background-audio-device-refreshing/55768>\
**Category:** Feature Requests\
**Created:** [April 12, 2023, 7:48pm UTC](https://forum.juce.com/t/background-audio-device-refreshing/55768 "2023-04-12T19:48:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruurdadema](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ruurdadema/32/15213_2.png) [@ruurdadema](https://forum.juce.com/u/ruurdadema)\
**Post date:** [April 12, 2023, 7:48pm UTC](https://forum.juce.com/t/background-audio-device-refreshing/55768/1 "2023-04-12T19:48:45Z")

</div>

In our application we build a list of all audio devices and all associated audio channels on a background thread. If we would do this on the main thread it would block the UI updates for too long, which we found out early on.

Unfortunately the audio backends schedule updates on the main thread themselves (using `AsyncUpdater`). This introduces a race condition between the background thread and the main thread (in `scanForDevices()`).

We would really like to have a way of controlling the device list change notification so we can schedule a refresh (call to `scanForDevices`) from our background thread ourselves.

Take for example CoreAudioIODeviceType. When the audio devices changes it calls `triggerAsyncUpdate()` which makes the main thread call `handleAsyncUpdate()` which calls `audioDeviceListChanged()`:

```auto
void audioDeviceListChanged()
{
    scanForDevices();
    callDeviceChangeListeners();
}

```

If we would be able to disable the call to `scanForDevices()` the problem would be solved and we would be fully safe refreshing the devices on the background thread:

```auto
void audioDeviceListChanged()
{
    if (!disableCallingScanForDevicesWhenDeviceListChanges)
        scanForDevices();
    callDeviceChangeListeners();
}

```
