You can start a worker thread that prints the dots. It's a little bit too complicated to show example code here, but basically you would follow this sequence:
MAIN THREAD
----------------------------------------
1. Call CreateEvent(NULL, FALSE, FALSE, NULL) to make an event the worker thread will use to know when to stop printing dots.
2. Call AfxBeginThread() to create the worker thread. Use the CREATE_SUSPENDED flag. Keep the returned pointer to CWinThread object.
3. Set the m_bAutoDelete member of the CWinThread object you get in step 2. If you don't do this, step 6 may cause a crash because the thread may cease to exist by the time you get around to wait for it to stop.
4. Call CWinThread::ResumeThread() on the CWinThread object you get in step 2. At this point the dots should start printing.
5. Call the function for which you wanted to print dots until it returns.
6. Once the function returns, call SetEvent() on the event you make previously, to stop the worker thread from printing dots.
7. Call WaitForSingleObject() on the m_hThread member of the CWinThread object you get in step 2.
WORKER THREAD
----------------------------------------
1. In a while() loop, call WaitForSingleObject() on the event created in step 1 of the main thread. Specify the desired rate of dot printing for the timeout parameter.
2. If WaitForSingleObject() returns WAIT_TIMEOUT, print a single dot and return to step 1. Otherwise, break out of the while() loop (proceed to step 3).
3. Return from the thread function or call AfxEndThread() to end the thread -- either way is fine.
3. Set to false the m_bAutoDelete member of the CWinThread object you get in step 2. If you don't do this, step 6 may cause a crash because the thread may cease to exist by the time you get around to wait for it to stop.
Also I forgot a step 8 in the main thread:
8. Delete the CWinThread (use "delete" operator on the pointer to the CWinThread object) to delete the worker thread object -- it is necessary to delete manually because m_bAutoDelete was set to false in step 3.
Argh, another mistake: (yes, I am a perfectionist)
3. Set to false the m_bAutoDelete member of the CWinThread object you get in step 2. If you don't do this, step 7 may cause a crash because the thread may cease to exist by the time you get around to wait for it to stop.
Are you allowed to modify the code in the function?
Because if you can, then you can easily create a true progress line which will indicate real progress and some implicit estimate of when the work will be finished.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.