Photo Screensaver

The Discussion

  • User profile image

    The Rnd.Next(int) is not working in Visual Studo 2008 (VB.NET).... What might be the problem here?

  • User profile image

    @Leigh:  That is since we don't do full source posting in our articles to reduce their length.  the Random object was declared in a global view.

    If you download the full source, you'll see this.

    In your application, you'll need to do something like Random rnd = new Random(DateTime.Now.Ticks);

    The ticks will seed the random number generator to be random.

  • User profile image

    I like this code very much, but I'm curious how I would go about having it work on both (dual) monitors?  I just don't think I'm familiar enough with the code itself to see where/what I need to change.  I want the screen saver to spread across both of them...

  • User profile image

    @Nick: Check out for a similar project (with source) that supports multiple monitors.

  • User profile image

    Why does nobody implement the /p preview functionality?!  If you actually *try* - there are some issues that you run into.  Namely - windows keeps re-running the screensaver (with the /p flag) each time you enter and exit the preview.  Your app needs to be smart enough to kill the previous one (or update it) and make sure that only one is running at any given time.

  • User profile image

    @Brock:  Sorry, we provide base code examples that are aimed at people beefing them out.

    Ping Arian, he may have a fully finished application.

  • User profile image

    Thanks for the example.

    I compiled it with VS2008 and it runs fine.

    One thing I noticed is a small problem with the memory usage. It is growing continuously while the screensaver runs. The problem seems to be in the ImageUpdater function and the ConstrainSize function.

    An example:

    int sourceHeight = sourcePhoto.SourceBitmap.Height;

    does create an bitmap through the get method, which is never released.

    It can be solved by creating a local bitmap object to which you assign sourcePhoto.SourceBitmap.

    At the end of the ConstraintSize function you can use the Dispose() method to release the memory of the local bitmap object.

    I hope this helps someone.

    The adjusted PhotoshowScreenSaver.cs file can be downloaded from my site.

  • User profile image

    Yeah, Joe is right, and there are plenty of places to manually handle the clean up in memory to keep the app lean. I watched task manager before and after making a few changes to both methods Joe mentioned. It kept the memory usage down.

Add Your 2 Cents