Solved

Communication between 2 instances of the same program

Posted on 2006-07-19
3
180 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now