SetForegroundWindow is a great solution. An alternative is to use the name Semaphores to send signals to other applications.
Finally, you can find the Inter-Process Communication (IPC) solution that lets you send messages between processes.
I wrote a simple .Net XDMessaging library that makes this very simple. Using it, you can send instructions from one application to another, and in the latest version even transfer serialized objects. This is a multicast implementation using the concept of channels.
App1:
IXDBroadcast broadcast = XDBroadcast.CreateBroadcast( XDTransportMode.WindowsMessaging); broadcast.SendToChannel("commands", "focus");
App2:
IXDListener listener = XDListener.CreateListener( XDTransportMode.WindowsMessaging); listener.MessageReceived+=XDMessageHandler(listener_MessageReceived); listener.RegisterChannel("commands"); // process the message private void listener_MessageReceived(object sender, XDMessageEventArgs e) { // e.DataGram.Message is the message // e.DataGram.Channel is the channel name switch(e.DataGram.Message) { case "focus": // check requires invoke this.focus(); break; case "close" this.close(); break; } }
source share