Creating a Cancel Dialog for lengthy operations

I'm trying to create a dialog that alows to cancel a running report generation.
I've tried alreade to do this with both of the AfxTreads (work thread and UI tread) but always with the result, that the dialog only appears after the report is sucessfully created and displayed in the dialog.
The calling sequence was as follows in the InitInstance() method of the dialog:

//Create Working Dialog
CWorkThread* pWorkThread = (CWorkThread*) AfxBeginThread(RUNTIME_CLASS(CWorkThread));

//Create the desired report
readData(m_iReportNo);      

return TRUE;  // Here ends the init dialog

Does anyone know a better way to do this or maybe the mistake I did?

Thanks for your help
UandIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brain2000Commented:
The problem is, the dialog will not be displayed until the InitInstance() returns.  You return from InitInstance() after you have called the readData() function, therefore the report will always be created first.

Try using CreateThread(...) to call the readData(...) function.  That way, it will not block returning from the InitInstance() dialog.

Another possibility is calling the readData() function from the CWorkThread class.  I assume CWorkThread is what is controlling the behavior of the dialog box.
0
SteveGTRCommented:
Try http://www.microsoft.com/MSJ/0297/wicked/wicked0297.htm it's simple and easy.

Good Luck,
Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abdijCommented:
Hi,
  In the main application call the Dialog for Cancelling the report generation and then Read the records. Dont do it in the initinstance() of the dialog cancel dialog.

Try.
All the best,
Bye
Abdij
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.