No rest for the weary [Free tool and source code to temporarily prevent a computer from entering sleep mode – now available for .NET, 32-bit, and 64-bit!]

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of

See you there!

Comments (41)
  1. Steve says:

    Which shows directly that not every program has to be 64bit, it's only worth it if you really need to address more memory, otherwise it will just use more. Exactly the reason why even tools like Visual Studio are only 32bit.

    And the comparison is of course not perfectly πŸ™‚ comparing WPF with the Windows API…

  2. Tom says:

    I hate to bring this up but I was kind of surprised you didn't mention it…  You should do a WinForms version as well before you pin the consumption on the .NET Framework.  I wrote a simple WinForms app awhile back which is similar to yours in many ways.  It has one very simple window, wraps a small bit of Win32 API, and is meant to be run minimized all the time.  I checked its memory usage using your same procedure and got the following results, targeting .NET Framework 4.0 Client Profile and 32-bit only (x86):

    Commit: 17032KB   Private: 7232KB

    Sure, that's still much larger than your native version, but it's also much smaller than your WPF version.

  3. David Anson says:


    I expect that one day 64-bit CPUs will no longer run 32-bit code – and then we'll be thankful we have native 64-bit applications (and .NET, of course). πŸ™‚ But for now you're totally right that some scenarios work perfectly well as 32-bit code!

  4. David Anson says:


    Great point – some (possibly significant) portion of that extra memory is due to WPF and wouldn't be present with WinForms. Thanks for keeping me honest! πŸ™‚ That said, I'm not out to criticize the .NET Framework here – whatever UI it's running. I initially wrote Insomnia in WPF because it was (and is!) my favorite application development platform for the desktop – this time around I used native code because it's (approximately) as efficient as I can get without resorting to assembly. It's a comparison of extremes, to be sure. πŸ™‚

  5. Phil says:

    Great idea, how has nobody thought of this?? But I need a version for ubuntu linux :-/ and based on how this app works I don't think running in WINE is going to be very productive!

  6. Gil says:

    Great if it would work. I get an error message of "The ordinal 380 could not be located in the Dynamic Link Library COMCTL32.dll. I using the 32-bit version. Any suggestions please?

  7. Kevin says:

    Same issue as GIl.

    Running XP Pro SP3.

  8. Brian says:

    Same issue as Gil and Kevin

  9. Jeff says:

    Same issue as GIl.

    Running XP Home 2002 SP3

  10. David Anson says:


    The issue you're seeing is that Windows XP is old enough that it does not support some of the APIs that native Insomnia uses. This topic was discussed in the comments of the original blog post – here's a link to my explanation there:…/give-your-computer-insomnia-free-tool-and-source-code-to-temporarily-prevent-a-machine-from-going-to-sleep.aspx

    As I say, I know what needs to be done to back-port to XP, but it hasn't been clear how necessary doing so is given that the .NET version of Insomnia runs fine on XP (according to all reports). If any of you have thoughts on the matter or reasons that the .NET version wouldn't work for you, I'd love to hear them.


  11. mUrAt says:

    You wouldn't happen to have made one to keep the monitor awake would you?  I leave my computer on 24/7 but, the monitor turns off after 15 min.  Which is fine unless I want to watch a video of some sort.  Then I either have to move the mouse every so often or change the settings.  Both of which gets annoying.  

  12. David Anson says:


    No, I haven't implemented a code to prevent the screen saver from kicking in. However, it's a request I've heard before and it's on my TODO list to think about. πŸ™‚

  13. Kevin says:

    Thanks David for the explanation of the XP SP3 issue.

    It's just that I found out about your app from Gizmo's Freewarre site and they said to ignore the .NET version. See below.

    "…The download is 0.4 MB, and is a Zip file containing 3 versions of the program.  One is the .NET version, which you can safely ignore…"

    Guess hey should have caveated that with "unless you are still running XP!

  14. David Anson says:


    Thanks for the info – I've just left a comment there to help others out! πŸ™‚

  15. Brian says:

    Thanks for addressing so quickly David. Did try the .NET version and works fine. Just trying to keep the mem usage to a minimum..

  16. mUrAt says:

    Thank you, I did find what I need from DontSleep.  But if you can come up with something better/smaller/easier, I'm sure it would be appreciated.

  17. ericc says:

    Doesn't work for me !

    Windows XP Professional SP3 with .NET framework 4.

    As the other, the native version doesn't start and give an error

    The .Net version start but the computer continue to act as usual, aka after 15min the screensaver is activated  and the machine locked.

    A detail may be, the icon of the application is not there !

    When the windows appear or in the tray, I have an empty white icon

  18. David Anson says:


    Sorry about the trouble! If you're not seeing the tray icon, Insomnia probably isn't running – and if it's not running, it can't prevent the machine from going to sleep. πŸ™‚ I'm not sure why the .NET version wouldn't work for you on XP because I've heard from other people that it works just fine for them. But maybe it doesn't matter too much – I've prioritized the task of making native Insomnia run on Windows XP, so you should be able to use that instead. I hope to have something to share in about a week or so and will blog about it once I do.

    Thanks for your patience!

  19. dadwhiskers says:

    When I try to download from:…/ – by clicking the link you provide, I get a server not found message every time.  "Firefox can't find the server at"

    Any suggestions?

  20. David Anson says:


    Please try again – maybe the server was down for a bit when you tried earlier? I've verified that it's up right now and the download link still works, so your download should succeed. If it still fails, you might try using a different machine or a different browser; perhaps something has gone weird with the one you've been using.

    Please let me know if you still have trouble after trying that!

  21. John B says:

    Excellent little utility and just what I was looking for. I am in a long distance relationship and sometimes we fall asleep togerther on cam (skype). It is a pain to keep the system alive other than the control panel. This solves all the problems. If a version comes with the ability to keep the screen alive as well (optional idealy) this would just be the icing on the cake.

    Thankyou very much!

  22. David Anson says:

    John B,

    What a great story – thanks for sharing! πŸ™‚ FYI that XP is at the top of my TODO list, but screen saver prevention is right after it.

    Thanks for your support!

  23. Robey says:

    Neat program David, but my problem is that my PC (under some sort of Group Policy that I can't get at, I assume) kicks in a screen saver after 5 minutes and then I have to enter my password to get back on.  It drives my potty – make a phone call and your PC needs a password again.

    I've been in the Registry and amended NoDispScrSavPage to zero so that I can at least get into screen saver settings but the option to change the wait time from 5 minutes, and the display logon screen on resume tick box, are greyed out.

    Can you help with that?


  24. David Anson says:


    The SetThreadExecutionState API Insomnia calls also exposes a ES_DISPLAY_REQUIRED flag which should keep the display on – however, the documentation explicitly says "This function does not stop the screen saver from executing.", so I don't think it's quite what you want. I think there are other programs out there that fake moving the mouse pointer periodically to simulate user interaction and which would probably accomplish your goal of preventing the screen saver.

    That said, the automatic password protection of your machines may be part of your company's security policy, so it may not be worth trying to bypass it. πŸ™‚

  25. Robey says:

    Many thanks for the response David.

    I quite appreciate what you say about bypassing security policies but I do think that 5 minutes is Draconian and unnecessary. I use the PC either at home or in the office with colleagues and in both cases there is nobody who would have a need or would gain a benefit from snooping – there's nothing especially confidential on it.

    Anyway, following your advice I found a program called Mouse Jiggler which seems to do the job admirably.


  26. Dave says:

    Brilliant little app. Just what I needed. And its crystal-clear simplicity is great.

  27. Hansen says:

    Hey, I just found this ap through a google search, since my problem is rather different, I have all sleep settings disabled for half a year now and yet, my PC (HP 425 laptop running XP professional) goes to sleep every other minute (no exaggeration, sometimes it goes to sleep while itΒ΄s not even woken up yet or goes to sleep while its already going to sleep, impossible), even while IΒ΄m halfway typing a word or clicking on a page.

    IΒ΄ve gotten grey hair since it started.

    It has no virusses or hardware conflicts, and after consulting X professionals, there was no solution except formatting, which IΒ΄ve been postponing.

    IΒ΄m running the application as we speak and IΒ΄m 8 minutes sleep-free so far!

    I feel like laughing my head off!!!


  28. RichMD says:

    Has this program been removed?  I keep finding dead links for the insomnia program

  29. David Anson says:


    No, sorry, it's still meant to be available. I switched my web hosting provider recently and the new on seems to have been down for about the past day. πŸ™ Please try again soon and I hope things will be working better – and if not, contact me via the contact form at the top right and I can email you the ZIP.

    Sorry for the trouble!

  30. Olly says:

    Great tool thanks. Group policy means my machine is liable to sleep at any time. Not any more πŸ™‚

  31. Jason says:

    Nice little utility, computer kept on sleeping while downloading files using my download manager (IDM) and it was pissing me off.  Was tired of always turning off sleep mode in Windows and then trying to remember to turn it back on.

  32. WormyWyrm says:

    My windows 8 home edition laptop falls asleep when the lid is closed (causing audio to cut out) regardless of if this is running or not.

  33. M2920 says:

    How do I install it?

  34. David Anson says:


    Download the ZIP file above, unblock it, and extract the contents to a new folder by right-clicking it and clicking "extract". Then run whichever Insomnia application you choose (ex: .NET, 32-bit, 64-bit).

    For info about unblocking, please see:…/unblockingdownloadedfile.aspx

  35. Papu says:


    Is there a way to set this up to run minimized with windows task schedulere?

  36. David Anson says:


    The .NET version supports a -minimize command-line flag that should make that easy:…/the-customer-is-always-right-updated-free-tool-and-source-code-to-prevent-a-machine-from-going-to-sleep.aspx

    Alternatively, you may be able to use one of the following tricks:…/run-a-bat-file-in-a-scheduled-task-without-a-window

    Hope this helps!

  37. Papu says:

    Thanks David!

  38. Bart Zorn says:

    Unfortunately, Insomnia doesn't work for me. My laptop goes to sleep 2 minutes after I close the lid. I have set every option I know to prevent it from sleeping, but nothing seems to work.

    Windows 7 SP1, all updates installed. Laptop is an Asus N53SV.

    Anyone any ideas?

    Thanks in advance!

  39. David Anson says:

    Bart Zorn,

    On many laptops, the default behavior when the lid is closed is to go to sleep. Windows treats this as a user-initiated action, so Insomnia isn't able to prevent it. If you want to change that behavior, you can do so in Control Panel's Power Settings – there will be an option to configure what closing the lid does and you can set it to "nothing" instead of "go to sleep".

    Hope this helps!

Comments are closed.