Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Temporarily Disable Screensaver in your WPF Code

Pete Brown - 25 September 2007

I wrote a small media player for my son. I wrote the original version in Silverlight, but quickly ran into a problem where no matter what I did, Silverlight wouldn't read the larger video files (encoding was fine, so I'm pretty sure this is a 1.1 alpha bug). Anyway, I rewrote it as a WPF app. The first time it ran, my wife realized I had forgotten something very important: the screensaver.

So I searched around, and everything I saw was about writing to the registry to disable the screensaver. That just didn't smell right to me, so I dug deeper.

Eventually I ran across this great post that shows how to response to the appropriate windows messages to block the screensaver from starting up. I tested it in my WPF app and it worked like a charm (however, it didn't handle the power/monitor blanking properly. hmm).

For what it's worth, here's a screenshot of the very simple babysit...umm, media player I wrote for Ben :)

(That's Bear in the Big Blue House: The Rhythm Masters song)

The buttons on the right generate random playlists: one has two random episodes and two random songs, another has four random songs, one random episodes, etc. Below the playlist is a list of all the media files in the "Bear" folder on my media server. You can click on any of them to play the video. It's all really simple, with the only style/template used being a simple button template I snagged from a blog a while back.

The app runs under .NET 3.5 (beta 2) on my wife's laptop just outside the kitchen.

posted by Pete Brown on Tuesday, September 25, 2007
filed under:      

2 comments for “Temporarily Disable Screensaver in your WPF Code”

  1. Skupsays:
    Glad it could help !
    I had seen such ugly things around the internet, like changing the monitor settings in the registry !! yerk !
    I had no problem with the monitor power event ? What was your issue ? how did you solve it ?
  2. Timsays:
    here, i found this, it might help you, works good for me B):

    Private Sub DisableScreenIdle()
    Dim ResetTimer As New Timers.Timer(5900)
    AddHandler ResetTimer.Elapsed, AddressOf ResetIdle
    End Sub

    Private Sub ResetIdle()
    End Sub

    Declare Function SetThreadExecutionState Lib "kernel32" (ByVal esFlags As Long) As Long

Comment on this Post

Remember me