Goal:
Open many programs which include same functions.
I implement the function from first program, and the other programs also want to implement the function.
They can use the function orderly till the function of first program have done.
Tool:
I found the "Mutex" can fulfil the purpose.
Meathod:
I programmed an easy program to test the function about the Mutex.
Opened two same programs(if they are A and B).
When I pressed the Button1 of A, it will count 5 seconds and show on screen.
If I pressed the Button1 of B inside the 5 seconds, it will starts to count till the A has done.
The result conformed with my anticipation!
BUT!!!
Sometimes, the B program crashed and showed "No response" on the windows.
I can use the B till the counter of A has done.
I can't find the question...
The following code is main code which I coded by MFC.
I hope someone can give me some suggestions.
Thanks a lot!!
CMutex mutex(false,_T("CodeProject"));
void CMutextestDlg::OnBnClickedButton1()
{
mutex.Lock();
CString str;
for(int i=0;i<=5;i++)
{
str.Format(_T("%d"),i);
SetDlgItemText(IDC_STATIC,str);
Sleep(1000);
}
SetDlgItemText(IDC_STATIC,_T("End"));
mutex.Unlock(); }