Link to home
Start Free TrialLog in
Avatar of UandI
UandI

asked on

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
Avatar of Brain2000
Brain2000
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abdij
abdij

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