Hi
Is it possible to make audio device watcher to detect if audio device is added or removed without timer?
I already made an watcher to do this with timer.
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(2)
};
_timer.Tick += UpdateDeviceList;
_timer.Start();
private void UpdateDeviceList(object sender, EventArgs e)
{
var currentDeviceList = new List<string>();
int deviceCount = Bass.BASS_GetDeviceCount();
for (int i = 0; i < deviceCount; i++)
{
var deviceInfo = Bass.BASS_GetDeviceInfo(i);
currentDeviceList.Add(deviceInfo.name);
}
// Check for added or removed devices
foreach (var device in currentDeviceList)
{
if (!_previousDeviceList.Contains(device))
{
Console.WriteLine($"Device added: {device}");
}
}
foreach (var device in _previousDeviceList)
{
if (!currentDeviceList.Contains(device))
{
Console.WriteLine($"Device removed: {device}");
}
}
// Update the previous device list
_previousDeviceList = currentDeviceList;
// Optionally update the UI
DeviceList.Items = currentDeviceList;
}
but this includes huge waste of CPU cycles so I want to find an another way.