public void RefreshConnectedDevices() { //ConnectedDevices = new ConcurrentDictionary<string, List<Guid>>(); var diDeviceInstances = DiInstance.GetDevices(); var connectedHandles = ConnectedDevices.Keys.ToList(); foreach (var device in diDeviceInstances) { if (!IsStickType(device)) { continue; } var joystick = new Joystick(DiInstance, device.InstanceGuid); var handle = JoystickToHandle(joystick); if (connectedHandles.Contains(handle)) { connectedHandles.Remove(handle); } if (ConnectedDevices.ContainsKey(handle)) { if (ConnectedDevices[handle].Contains(device.InstanceGuid)) { continue; } } else { ConnectedDevices[handle] = new List <Guid>(); } ConnectedDevices[handle].Add(device.InstanceGuid); } foreach (var connectedHandle in connectedHandles) { ConnectedDevices.TryRemove(connectedHandle, out _); } }