private static void SetWithTimeout(AudioWrapper wrapper, AudioWrapper.EDataFlow flow, AudioWrapper.ERole role,
                                           string devId, int timeout)
        {
            var endTime = Environment.TickCount + timeout * 1000;

            for (;;)
            {
                wrapper.SetDefaultDevice(flow, role, devId);
                if (wrapper.GetDefaultDevice(flow, role) == devId || (timeout != -1 && Environment.TickCount > endTime))
                {
                    return;
                }
                Thread.Sleep(1000);
            }
        }