Board index » cppbuilder » About the mutex...
Robert Huang
![]() CBuilder Developer |
About the mutex...2008-01-07 09:18:52 AM cppbuilder37 Hi, all. I have a question about the mutex. I want to execute program-A by B, so I place the code in program-B like this: //--------------------------------------------------------------------------- void __fastcall TBForm::ButtonExeClick(TObject *Sender) { HANDLE TargetMutex = OpenMutex(SYNCHRONIZE, false, "Program-A"); if(TargetMutex == NULL) WinExec(ExeATitle.c_str(), SW_SHOW); else ShowMessage("Already in running!!"); } //--------------------------------------------------------------------------- And in program-A will be like this: HANDLE Mutex; //--------------------------------------------------------------------------- __fastcall TAForm::TAForm(TComponent* Owner) : TForm(Owner) { Mutex = CreateMutex(NULL, false, "Program-A"); } //--------------------------------------------------------------------------- void __fastcall TAForm::FormClose(TObject *Sender, TCloseAction &Action) { ReleaseMutex(Mutex); Action = caFree; } //--------------------------------------------------------------------------- When A is running, the message "Already in running!!" will appear. But when A is terminated, the message will still appear. How do I fix the problem? Thx:) |