Link to home
Start Free TrialLog in
Avatar of AVaulin
AVaulinFlag for Ukraine

asked on

Appliction instances synchronization

I wanna know how to synchronize some instances of my application. Imagine that apllication reads ini-file, prepare GUI controls and waits for user action. Second/third application instance can edit ini-file so first instance can interprets ini-file in non correct way. So the question is how to send notification from one instance and how to recieve that message in another instances.
Avatar of AlexVirochovsky
AlexVirochovsky

I think, best way is using Syncronization metod Mutex
with Api CreateMutex,OpenMutex,
ReleaseMutex. I use this metod
for test existance of same instance,
you can test open some file:
say CreateMutex(and test by opened) befor open , and ReleaseMutex after close.
I hope, it helps. Alex.
BTWE: If you want i can send you my code (tomorrow).

Avatar of AVaulin

ASKER

I'll wait for tomorrow. But I'm know all (or almost all) about Mutex functions. I want to notify and recieve notification at run-time. Read question more carefull. Waiting for tomorrow (or for your code)...
1.
>>I'm know all (or almost all) about Mutex
so , you don't need my code, but:

  HANDLE hMutex = CreateMutex(NULL,TRUE, "wkadip_mutex");
  if (hMutex)//real one? MUTEX_ALL_ACCESS
    {
      if (GetLastError() != ERROR_ALREADY_EXISTS)
        {
          .....
         App.Run();
            }
        }
      CloseHandle(hMutex);
2. For  
>>can interprets ini-file in non correct way
You can simple use LockFile Api!
Avatar of AVaulin

ASKER

Sorry, I can't accept this answer. I don't want lock file. I want to know if one instance changed it. Other words: imagine dialog-based application with only one check-box control. You can run more than one instances. Check-box state changing in one instance must chagne state in all another. How can I do that?
ASKER CERTIFIED SOLUTION
Avatar of mflam
mflam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When receiving the WM_COMMAND with BN_CLICKED notification for the first control , send the second window a message ( or Set an event that will release a thread waiting ) to change the check box .
Avatar of AVaulin

ASKER

This is not an answer I waited for. But it gave me a start point to find answer by meself.