Solved

Communication between 2 instances of the same program

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now