?
Solved

Communication between 2 instances of the same program

Posted on 2006-07-19
3
Medium Priority
?
186 Views
Last Modified: 2010-04-30
I have a program that acts as a scheduler. It is possible to open mutliple instances of this program on the same machine (several people can edit the different schedules at one time ). Only one program however should be acting as the scheduler.

When an instance of the program is started I want it to check for other instances
- if there are no other instances then it should become the scheduler

When an instance of the program closes and it is the scheduler, it needs to look for another instance and tell that instance to become the scheduler.

Also, the apps will be running on a terminal server by different users.


Thanks
0
Comment
Question by:tricks801
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17145373
you only need to write 1 server and 1 client.

0
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 2000 total points
ID: 17147574
You can do that many ways.
------
On startup you can check the number that is returned from app.PrevInstance.  If > 0 then you set the program as a client - else it becomes a server.  A communication method such as TCP-IP will need to be set up and when the server exits a poll will need to be taken to decide who becomes the next server.
------
On startup open a common database and add itself using app.hInstance to a table.  If the autonum ID generated is the lowest (or there is only one row in the table) then it is the server - else it is a client.  On exit - delete the row from the table.  When an event hapes that needs to be acted on - only the app with the lowest autonum will act on it - becomming the server

These are only two I can think of off the top of my head.  It all depends on what you are comfortable with and familiar with.  If you know databases or TCPip - or even Windows Messaging.  It will also depend on the method you are already using for data storage and retrieval - what you are scheduling.

Rob
0
 
LVL 4

Expert Comment

by:JRCSystems
ID: 17287273
Tricks801: Is this still open? Where did you get with this?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question