Hello
If I have two programs running at the same time, what is the best way to share gloval values from modules in each program?
Right now I can pass arguments when application 1 calls the system dianostic.start to start application 2 but then there is no back and forth communication between the two.
I want to make some decisions on application 1 based on results from application 2.
Do i must use .net remoting or namedPipes even though it is running on one machine only?
Is therean easy way to just get gloval variables values from app 2 to app 1?
like have app2 set a gloval variable to a new value and then have app 1 set its gloval value to app's 2 gloval value?
thanks
AlanPosted Aug 22, 2008, 4:30 PM
One thing that just occurred to me, Juan, is that you could use the FileWatcher class to be alerted when a change is made to the text file by the other application.
Here's a link to the docs if you're not already familiar with it:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
Juan ColladoPosted Aug 25, 2008, 7:34 AM
That is great!
That is much easier than working with .net remoting for simple same machine tasks.
Thank you very much Alan.
Juan ColladoPosted Aug 22, 2008, 4:23 PM
Thank you
I follow your advice and use a file.
AlanPosted Aug 22, 2008, 3:58 PM
If both applications will already have an open connection to SQL Server, then that would be a reasonable way to do it.
Otherwise it's a bit heavy and certainly slower than using a simple text file.
There's nothing wrong with using the clipboard to transfer data between applications but it's not very robust - the user might inadvertently use the clipboard for some other operation before the first application has time to read it.
Remoting is complicated and it can be difficult to get it to work reliably across process boundaries. There's also the newer WCF which is supposed to be easier than remoting but I've never used it and so can't testify to its efficacy.
Juan ColladoPosted Aug 22, 2008, 12:58 PM
Thanks Alan
I guess the file solution sounds simpler.
Would it work the same or slower if I just have app 1 update a set of fields in a table and have each application update its value?
is that slower to access in SQL Server 2005?
Right now I actually had it working by writing to the clipboard because I had to get something working for the company but it makes me feel stupid to do it that way.
is .net remoting too complicated for something like this?
thanks
AlanPosted Aug 22, 2008, 12:00 PM
Well, the easiest way is for one application to write values to a disk file which the other application then reads.
The problem, of course, is synchronization. If the first application uses the System.Diagnostics.Process class to launch the second and the second writes values to the file before exiting, the first application can simply wait until the second has exited by calling the Process.WaitForExit() method. It can then read the values from the file and delete it.
Otherwise, it's a matter of polling the file until the values arrive and having a simple way of ensuring that you're reading the latest values if the process is to be repeated.
If this approach is not sophisticated enough for what you need to do, then I'd look at either named pipes or shared memory.
Shared memory is very fast and reliable but it needs a ton of API calls to set up.
Named pipes are a good way of providing two way communication between processes on a single computer as they don't require a network transport and so are quite simple and fast. The drawback is that they can only deal with streams of bytes (so you need to deserialize to other data types) and you need to decide on some sort of protocol between the two applications so that they don't attempt to write to the stream at the same time.