I want to pass a message from windows service to an windows desktop application that is already running. I have implemented a timer on windows service. after an interval the service send a message to the windows application.
The service or sender code is below:
System.Diagnostics.Process[] lProcs = System.Diagnostics.Process.GetProcessesByName("TestProcess2");
if (lProcs.Length > 0)
{
IntPtr handle = lProcs[0].MainWindowHandle;
if (handle != IntPtr.Zero)
SendMessage(handle, 232, IntPtr.Zero, IntPtr.Zero);
}
and the windows desktop application (receiver) code are as follows:
protected override void WndProc(ref Message m)
{
if (m.Msg == 232)
{
MessageBox.Show("Received");
}
else
{
base.WndProc(ref m);
}
}
the above code is working fine when both process are windows desktop application. when i used windows service as a sender then the windows desktop application process can not receive the message. Can you help me please?