How to properly dispose multiple forms
<p><strong>Question</strong>: How to properly dispose the ScreenSaverForm(s) that is created in the method <code>ShowScreensaver</code>?</p>

<p>When I run CODE ANALYSIS from Visual Studio it reports the following: <code>In method 'Program.ShowScreenSaver()', call System.IDisposable.Dispose on object 'ssf' before all references to it are out of scope</code>.</p>

<p>I don't understand how to do that because the Application enters an anonymous message loop afters exiting method <code>ShowScreenSaver()</code>. Only the screensavers themselves can stop the application by calling <code>Application.Exit()</code> on mousemove-event. <strong>Should the screensaverForms dispose themselves perhaps?</strong></p>

<pre><code>static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
                ShowScreenSaver();
                Application.Run();
    }

    /// &lt;summary&gt;
    /// Display the form on each of the computer's monitors.
    /// &lt;/summary&gt;
    static void ShowScreenSaver()
    {
        ScreenSaverForm ssf;
        foreach (Screen screen in Screen.AllScreens)
        {
            ssf = new ScreenSaverForm(screen.Bounds);
            ssf.Show();
        }
    }
}
</code></pre>

<p>Simplified code of the Screensaver class</p>

<pre><code>public partial class ScreenSaverForm : Form
{
    public ScreenSaverForm()
    {
        InitializeComponent();

        //Display pretty image
        ShowprettyImage();
    }
    private void ScreenSaverForm_MouseMove(object sender, MouseEventArgs e)
    {
        if (!mouseLocation.IsEmpty)
         {
             // Terminate if mouse is moved a significant distance
             if (Math.Abs(mouseLocation.X - e.X) &gt; 25 ||
                 Math.Abs(mouseLocation.Y - e.Y) &gt; 25)
                 Application.Exit();
         }

         // Update current mouse location
         mouseLocation = e.Location;
    }
}
</code></pre>
