/// <summary>
        /// Polls and updates the statuses of connected monitors.
        /// </summary>
        private void PollMonitors()
        {
            // All monitors are considered inactive until proven otherwise.
            var inactive = new List <Monitor>();

            inactive.AddRange(Monitors);

            for (uint adapterIndex = 0;; adapterIndex++)
            {
                var first = false;

                var adapter = new DisplayDeviceW();
                adapter.Cb = (uint)Marshal.SizeOf(adapter);

                if (!User32.EnumDisplayDevicesW(null, adapterIndex, ref adapter, 0))
                {
                    break;
                }

                // If the adapter is inactive - continue;
                if ((adapter.StateFlags & DisplayDeviceStateFlags.Active) == 0)
                {
                    continue;
                }

                if ((adapter.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0)
                {
                    first = true;
                }

                uint displayIndex;
                for (displayIndex = 0;; displayIndex++)
                {
                    var display = new DisplayDeviceW();
                    display.Cb = (uint)Marshal.SizeOf(display);

                    if (!User32.EnumDisplayDevicesW(adapter.DeviceName, displayIndex, ref display, 0))
                    {
                        break;
                    }

                    // If not active - continue;
                    if ((display.StateFlags & DisplayDeviceStateFlags.Active) == 0)
                    {
                        continue;
                    }

                    // If active - remove from inactive list.
                    // If something was removed, that means this display exists in the monitor array.
                    if (inactive.RemoveAll(x => x.Name == display.DeviceName) > 0)
                    {
                        continue;
                    }

                    UpdateMonitor(new Win32Monitor(adapter, display), true, first);
                }

                // HACK: If an active adapter does not have any display devices (as sometimes happens), add it directly as a monitor.
                if (displayIndex != 0)
                {
                    continue;
                }

                // Remove self from inactive list.
                if (inactive.RemoveAll(x => x.Name == adapter.DeviceName) > 0)
                {
                    continue;
                }

                UpdateMonitor(new Win32Monitor(adapter, null), true, first);
            }

            foreach (Monitor inactiveMonitor in inactive)
            {
                UpdateMonitor(inactiveMonitor, false, false);
            }
        }