Exemple #1
0
        /// <summary>
        /// get all devices connected to computer
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Device> GetConnectedDevices()
        {
            if (System.Threading.Thread.CurrentThread.IsBackground)
            {
                Utility.LogMessage("[GetConnectedDevices] [IsBackground]");
            }

            var devices = new List <Device>();

            try
            {
                _connectedDeviceCollection.Clear();
                _connectedDeviceCollection.Refresh();
                foreach (var connectedDevice in _connectedDeviceCollection)
                {
                    try
                    {
                        connectedDevice.Connect();

                        var deviceObj = new Device()
                        {
                            Id          = connectedDevice.DeviceId,
                            DisplayName = connectedDevice.FriendlyName,
                        };

                        if (!devices.Contains(deviceObj))
                        {
                            devices.Add(deviceObj);
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        connectedDevice.Disconnect();
                    }
                }
            }
            catch
            {
                throw;
            }

            return(devices);
        }
Exemple #2
0
        /// <summary>
        /// get all devices connected to computer
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Device> GetConnectedDevices()
        {
            var devices = new List <Device>();

            try
            {
                _connectedDeviceCollection.Clear();
                _connectedDeviceCollection.Refresh();
                foreach (var connectedDevice in _connectedDeviceCollection)
                {
                    try
                    {
                        connectedDevice.Connect();

                        var deviceObj = new Device()
                        {
                            Id          = connectedDevice.DeviceId,
                            DisplayName = connectedDevice.FriendlyName,
                        };

                        if (!devices.Contains(deviceObj))
                        {
                            devices.Add(deviceObj);
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        connectedDevice.Disconnect();
                    }
                }
            }
            catch
            {
                throw;
            }

            return(devices);
        }