Automatic desktop wallpaper change
<p>I am trying to change the desktop wallpaper in every 5 mins automatically (for debugging purpose it's configured to 5 seconds).</p>

<p>I found some standard method for calling SystemParametersInfo() API from .net code with standard parameters to it. </p>

<p>I did them. But I found that it picks up only the Bmp files. I am having a huge collection of Jpg which I prefer to put on Desktop.</p>

<p>Well I found some suggestions to convert the Jpg into Bmp using Image.Save() method. I don't prefer this.</p>

<p>What is the direct method to have the Jpg set on the desktop? I guess User32.dll should provide a way to it.</p>

<p>Here is the code for your reference:</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Timers;

namespace ChangeWallpaper
{
    class Program
    {
        [DllImport("user32.dll")]
        public static extern bool SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, string pvParam, UInt32 fWinIni);
        static FileInfo[] images;
        static int currentImage;

        static void Main(string[] args)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(@"C:\TEMP");
            images = dirInfo.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);

            currentImage = 0;

            Timer imageChangeTimer = new Timer(5000);
            imageChangeTimer.Elapsed += new ElapsedEventHandler(imageChangeTimer_Elapsed);
            imageChangeTimer.Start();

            Console.ReadLine();
        }

        static void imageChangeTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            const uint SPI_SETDESKWALLPAPER = 20;
            const int SPIF_UPDATEINIFILE = 0x01;
            const int SPIF_SENDWININICHANGE = 0x02;

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, images[currentImage++].FullName, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);            
            currentImage = (currentImage &gt;= images.Length) ? 0 : currentImage;
        }
    }
}
</code></pre>
