WaitForSingleObject() Question Again!!!!
-
I'm developing a program required to use Synchronization function WaitForSingleObject(). It may take several seconds or longer to run this function, therefore, I want to add a Progress Bar control to let the user knows how long do they need to wait. However, I cannot find the source code of this WaitForSingleObject() function, so I cannot put the progress bar SetPos() in that function. I've tried to set the progress bar move by timer...but when the program run WaitForSingleObject(), the progress bar stopped and start move again after WaitForSingleObject(). Can I do it in this way???:: If originally the timeout value is 16000....(WaitForSingleObject(xxxx, 16000)), then I split it into ... let say....5 ......e.g.: WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; So that the progress bar can update every 3200 time interval?..... Or do anyone have another suggestion on using WaitForSingleObject with Progress Bar?? I must use this WaitForSingleObject function...... Sorry...I just a beginner in MFC programming;P
-
I'm developing a program required to use Synchronization function WaitForSingleObject(). It may take several seconds or longer to run this function, therefore, I want to add a Progress Bar control to let the user knows how long do they need to wait. However, I cannot find the source code of this WaitForSingleObject() function, so I cannot put the progress bar SetPos() in that function. I've tried to set the progress bar move by timer...but when the program run WaitForSingleObject(), the progress bar stopped and start move again after WaitForSingleObject(). Can I do it in this way???:: If originally the timeout value is 16000....(WaitForSingleObject(xxxx, 16000)), then I split it into ... let say....5 ......e.g.: WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; WaitForSingleObject(xxxx, 3200); Call ProgressBarControl; So that the progress bar can update every 3200 time interval?..... Or do anyone have another suggestion on using WaitForSingleObject with Progress Bar?? I must use this WaitForSingleObject function...... Sorry...I just a beginner in MFC programming;P
Instead of WaitForSingleObject could you not use MsgWaitForMultipleObject just before the thread is about to do it's stuff create a Timer that fires every second. when MsgWaitForMultipleObjects returns determine what's happened has the thread finished or do you have a windows msg i.e. WM_TIMER. if this is appropriate you could have a class variable that indicates what step the thread is up to - wrapped by a CriticalSection so you can update your UI accordingly.