473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with remotly turn on/off monitor

4
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?

Expand|Select|Wrap|Line Numbers
  1. public delegate void SendMessageCallback(int hWnd, int hMsg, int wParam, int lParam);
  2.  
  3. public int WM_SYSCOMMAND = 0x0112;
  4. public int SC_MONITORPOWER = 0xF170;
  5.  
  6. [DllImport("user32.dll")]
  7. private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
Expand|Select|Wrap|Line Numbers
  1. public void OnDataReceived(IAsyncResult asyn)
  2. {
  3.     SocketPacket socketData = (SocketPacket)asyn.AsyncState;
  4.  
  5.     try
  6.     {
  7.         int iRx  = socketData.currentSocket.EndReceive(asyn);
  8.         char[] chars = new char[iRx + 1];
  9.  
  10.         Decoder d = Encoding.UTF8.GetDecoder();
  11.         int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0);
  12.  
  13.         String szData = new String(chars);
  14.  
  15.         if (szData.ToString().Substring(0, 4) == "1040")
  16.         {
  17.             SendMonitorMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);
  18.         }
  19.     }
  20.     catch { }
  21. }
Expand|Select|Wrap|Line Numbers
  1. private void SendMonitorMessage(int hWnd, int hMsg, int wParam, int lParam)
  2. {
  3.     if (InvokeRequired)
  4.     {
  5.         this.Invoke(new SendMessageCallback(this.OnSendMonitorMessage), new object[] { hWnd, hMsg, wParam, lParam });
  6.     }
  7.     else
  8.     {
  9.         this.OnSendMonitorMessage(hWnd, hMsg, wParam, lParam);
  10.     }
  11. }
  12.  
  13. private void OnSendMonitorMessage(int hWnd, int hMsg, int wParam, int lParam)
  14. {
  15.     SendMessage(hWnd, hMsg, wParam, lParam);
  16. }
Aug 23 '10 #1
1 1798
Christian Binder
218 Expert 100+
Did you try using breakpoints an look whats happening?
Maybe you also take a look into window's error-log/event-viewer.
Aug 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
5
by: ste | last post by:
this code not work: it is no possible Exit from Monitor Why ? thank ste //////// using System; using System.Collections;
15
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...
6
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...
1
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...
2
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...
0
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...
5
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...
1
Ali Rizwan
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.