See all the coments...
Looks like
PostMessage
instead of
SendMessage
was the solution and solved by OP.
Comment snippet:
Try something like this. I will not google it for you ;) And of course set the right parameters where I simply put a 0.
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void button1_Click(object sender, EventArgs e)
{
PostMessage(new IntPtr(), 0, (IntPtr)0, (IntPtr)0);
}
This based on this CP Article:
Programmatically Turning on the Screen Saver[
^]
[Edit]
Correction from OP:
PostMessage(
new HandleRef(null, new IntPtr((int)SpecialHandles.HWND_BROADCAST)),
WM_SYSCOMMAND,
new IntPtr( SC_SCREENSAVE),
new IntPtr( 0));