How to properly turn off monitor power in C #?

I already use some kind of code to turn off the power of the monitor, but I still have a little problem.

This code works fine many times, but after a while the monitor becomes empty. I mean, the screen is completely black, you can’t see anything, but you can see that it is still on. The LCD indicator is still on, but the screen is completely black.

I have no idea why this is happening, maybe some of you know why ... This will never happen if I set up Windows Power settings to turn off the monitor in X minutes, but I need an application for this so that I can call it a label whenever you want.

The code I use looks something like this:

[System.Runtime.InteropServices.DllImport("user32.dll")] private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam); const int WM_SYSCOMMAND = 0x0112; const int SC_MONITORPOWER = 0xF170; const int HWND_BROADCAST = 0xFFFF; SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2); 

Any ideas?

+4
source share
4 answers

You do not want to send this message to all windows. You rely on each of them to process it as you expect.

You need to create your own and only send a message so that you can control the behavior.

There are several solutions in the comments on this post by Raymond Chen: http://blogs.msdn.com/oldnewthing/archive/2006/06/13/629451.aspx

+4
source

Have you tested this on multiple machines? There may be a problem with the driver ...

+1
source

Nothing worked, I created my own window and used this Window handle and most of the time, the screen is off and completely black (LCD off), but from time to time the LCD doesn’t turn off ...: (

0
source

I have this problem too. machines often work fine, and then for some well-known reason they will not allow the screens to sleep. I cannot find a specific community.

This happens even when the machines exit the system. Usually 1 reboot fixes the problem. Not always.

I even saw the screens wake up and refuse to sleep again on the machine that exited the system, and no one interacted with it.

Obviously, there is some process or processes to blame, but how do you track them?

0
source

All Articles