public static void SetWallpaper(string imagePath)
        {
            EnableTransitions();

            if (Environment.OSVersion.Version.Major >= 8)
            {
                // TODO Support multiple monitors
                DesktopWallpaperFactory.Create().SetWallpaper(null, imagePath);
                SyncVirtualDesktops(imagePath);
            }
            else
            {
                ThreadStart threadStarter = () =>
                {
                    IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop();
                    _activeDesktop.SetWallpaper(imagePath, 0);
                    _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE);

                    Marshal.ReleaseComObject(_activeDesktop);
                    SyncVirtualDesktops(imagePath);
                };
                Thread thread = new Thread(threadStarter);
                thread.SetApartmentState(ApartmentState.STA);  // Set the thread to STA (required!)
                thread.Start();
                thread.Join(2000);
            }
        }
        public static void SetWallpaper(string imagePath)
        {
            ThreadStart threadStarter = () =>
            {
                IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop();
                _activeDesktop.SetWallpaper(imagePath, 0);
                _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE);

                Marshal.ReleaseComObject(_activeDesktop);
            };
            Thread thread = new Thread(threadStarter);

            thread.SetApartmentState(ApartmentState.STA);  // Set the thread to STA (required!)
            thread.Start();
            thread.Join(2000);
        }
Beispiel #3
0
        public static void SetWallpaper(string imagePath)
        {
            EnableTransitions();

            ThreadStart threadStarter = () =>
            {
                IActiveDesktop _activeDesktop = ActiveDesktopWrapper.GetActiveDesktop();
                _activeDesktop.SetWallpaper(imagePath, 0);
                _activeDesktop.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE);

                Marshal.ReleaseComObject(_activeDesktop);
            };
            Thread thread = new Thread(threadStarter);

            thread.SetApartmentState(ApartmentState.STA);  // Set the thread to STA (required!)
            thread.Start();
            thread.Join(2000);

            if (UwpDesktop.IsRunningAsUwp())  // Ensure wallpaper registry setting gets updated
            {
                UpdateRegistrySettings(imagePath);
            }
        }