tray program + external applications

  • Thread starter Thread starter Robert Samuel White
  • Start date Start date
R

Robert Samuel White

Hi there. Can anyone point me to some good references or examples on how to
create an independent tray program that can send triggers to external
applications all designed inside the same solution?

Basically, I want a tray program with a context menu of options (they can be
checked or unchecked options) that when an action is taken gets triggered to
all the other open applications of the solution. I've already created the
tray program, but I don't know how to accomplish the second part. For now,
I have it set up to show the state of these checks in the registry, and each
application on a timer of one second checks for changes in the registry.
Obviously, this is not the best way.
 
Robert said:
Hi there. Can anyone point me to some good references or examples on
how to create an independent tray program that can send triggers to
external applications all designed inside the same solution?

Basically, I want a tray program with a context menu of options (they
can be checked or unchecked options) that when an action is taken
gets triggered to all the other open applications of the solution.
I've already created the tray program, but I don't know how to
accomplish the second part. For now, I have it set up to show the
state of these checks in the registry, and each application on a
timer of one second checks for changes in the registry. Obviously,
this is not the best way.

You could use .Net Remoting. This has the advantage of being easily
extendable to have your applications communicate over a network, and it also
has the advantage of being strictly managed code.
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconnetremotingoverview.asp

If you're willing to delve into Win32 API calls, there are a few options for
Interprocess Communication, the most useful of which would probably be
pipes.
http://msdn.microsoft.com/library/en-us/ipc/base/pipes.asp
 
Thanks, Sven, I'm going to look into this. I'd prefer to stick with .NET
rather than deleve into the Win32 API as I've never done that. I've
primarily developed in Access, Visual Basic, Pascal, Java, and PHP.

Do you happen to know how to check for a running application? And if it is
not running, to execute it? I'm not sure where to start. Basically, the
front-end applications need to check to see if the tray program is even
running. If it's not, then it needs to open it up. From there, the tray
program forces the user to log in before the front-end applications may be
accessed.

I'm trying to port a sophisticated multi-user, networked, multi-database,
multi-application suite written in Access to .NET.

-Samuel
http://rswfire.com
http://enetwizard.net
 
Robert said:
Do you happen to know how to check for a running application? And if
it is not running, to execute it? I'm not sure where to start.
Basically, the front-end applications need to check to see if the
tray program is even running. If it's not, then it needs to open it
up. From there, the tray program forces the user to log in before
the front-end applications may be accessed.

There are typically three ways in which an application can check if an
instance of itself or another application is already running. One is
enumerating all windows looking for one with a specific title (for a tray
app this window would typically be invisible). One is checking the list of
running process to see if the executable is running. The last one is using
named pipes. The application that needs to be checked typically creates a
named pipe, and the application that does the checking tries to connect to
it. If that works, the application is running.

Unfortunately, only the last one is a truly robust method, and as it
requires pipes so it can't be done in pure .Net. The behaviour however can
be emulated using .Net Remoting. Simply have the tray app be a host
application, have it listen on some port with some URI (see the link I
provided with info on how to do all this, it contains a very simple example
of a host and client app), then have the other application be a client, and
attempt to connect to the remoting channel on the localhost. If that fails,
the tray app is not running, so you must launch it using CreateProcess.

For all the communication the other way around, the tray app is the remoting
client to the other applications, which act as host in that scenario.

I suggest you read the documentation on .Net Remoting thoroughly.
 
Sven said:
channel on the localhost. If that fails, the tray app is not running,
so you must launch it using CreateProcess.

Oops, CreateProcess is Win32 API, use Process.Start in .Net.
 
Back
Top