Solved

Communication between 2 instances of the same program

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now