Solved

Communication between 2 instances of the same program

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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
Course of the Month4 days, 7 hours left to enroll

635 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