Hi!
I'm trying to remotly turn on/off my monitor using this code below. The problem is whenever I call the method that turn on/off the monitor from within the tcp asynchronous receive data method, the application just ends with no exception. So i put in a delegate but the same problem was still there.
What is the correct way of doing this? - public delegate void SendMessageCallback(int hWnd, int hMsg, int wParam, int lParam);
-
-
public int WM_SYSCOMMAND = 0x0112;
-
public int SC_MONITORPOWER = 0xF170;
-
-
[DllImport("user32.dll")]
-
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
- public void OnDataReceived(IAsyncResult asyn)
-
{
-
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
-
-
try
-
{
-
int iRx = socketData.currentSocket.EndReceive(asyn);
-
char[] chars = new char[iRx + 1];
-
-
Decoder d = Encoding.UTF8.GetDecoder();
-
int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0);
-
-
String szData = new String(chars);
-
-
if (szData.ToString().Substring(0, 4) == "1040")
-
{
-
SendMonitorMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);
-
}
-
}
-
catch { }
-
}
- private void SendMonitorMessage(int hWnd, int hMsg, int wParam, int lParam)
-
{
-
if (InvokeRequired)
-
{
-
this.Invoke(new SendMessageCallback(this.OnSendMonitorMessage), new object[] { hWnd, hMsg, wParam, lParam });
-
}
-
else
-
{
-
this.OnSendMonitorMessage(hWnd, hMsg, wParam, lParam);
-
}
-
}
-
-
private void OnSendMonitorMessage(int hWnd, int hMsg, int wParam, int lParam)
-
{
-
SendMessage(hWnd, hMsg, wParam, lParam);
-
}
1 1798
Did you try using breakpoints an look whats happening?
Maybe you also take a look into window's error-log/event-viewer.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mark Berkhoff |
last post by:
Hi,
The db2 fault monitor coordinator (db2fmcd) that monitors the fault monitors
of my db2 instances does not seem to restart the fault monitor (db2fmd) when
it exits.
We use db2 v8.1 fixpack...
|
by: ste |
last post by:
this code not work: it is no possible Exit from Monitor
Why ?
thank
ste
////////
using System;
using System.Collections;
|
by: mrpolitics |
last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd)
and everything was fine untill yesterday when the server crashed. So I did
a cold restart and staretd the server back up...
|
by: Yeah |
last post by:
I just purchased a Samsung 930B flat-panel monitor. Its *recommended*
resolution is 1280x1024.
I was previously running at 1024x768, but I also work with graphics. Any
images that were square or...
|
by: vijay.db |
last post by:
Hi group,
Have a problem with event monitor so my db2diag.log is getting filled
like any thing..
Running DB2 V8.1 Fixpack 6 in AIX server.
Created a event monitor and redirecting it's...
|
by: cruddpuppet |
last post by:
My school computer has monitor issues (turns off every 2 minutes) and I have to constantly turn it back on. I don't have the software or the privelages to install the software needed to scan for...
|
by: okonita |
last post by:
Hi all,
I am attempting to create a event monitor and comming up with error. Here's my statement that is failing: "db2 create event
monitor afcarprd for statements, tables, transactions write to...
|
by: jbenner |
last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause...
|
by: Ali Rizwan |
last post by:
Hi all,
I don know how windows turn monitor or harddisk off??? I want to add same feature in my app so that my app can be a power saving app for laptops. I want to use different poweschemes as we do...
|
by: AliRezaGoogle |
last post by:
Dear Members,
I have a problem in the concepts of Monit.Enter and Monitor.Exit
(Before everything I should say that I know how to solve this problem
by
using Monitor.Wait and I do not need a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |