Modeless dialog box in a thread
Hi,
I have a multi-threaded application. In the application there is a class
CDiskSpaceWarn corresponding to a modeless dialog box that I need to create
in DiskSpaceCheck thread which is spawned in the Application main dialog's
Oninitdialog method.
Here is the definition of the thread:
UINT ThreadDiskSpaceWarn(LPVOID pvoid)
{
extern CDiskSpaceWarn *pdlg;
long unsigned int timer=0;
ULARGE_INTEGER ll,pp,oo;
pdlg = new CDiskSpaceWarn;
GetDiskFreeSpaceEx(NULL,&ll,&pp,&oo);
float fDiskNum= (static_cast<float>(static_cast<__int64>(oo.QuadPart /(1024
* 1024))))/1000;
for(int i=0;1==1;++i)
{
if(fDiskNum<20.0)
{
pdlg->Create(IDD_DISKSPACEWARN,AfxGetApp()->m_pMainWnd);
pdlg->ShowWindow(SW_SHOW);
pdlg->CenterWindow(NULL);
pdlg->RunModalLoop();
}
Sleep(3600000);
if(!threadDiskSpaceWarn) //Closing?
break;
}
return(0);
}
The EndDialog menthod for this modeless dialog is overridden as follows:
void CDiskSpaceWarn::OnOK()
{
// TODO: Add extra validation here
pdlg->EndModalLoop(100);
pdlg->DestroyWindow();
CDialog::OnOK();
}
The thread is doing nothing but checking the hard diskps space every one hr
and brings up a modeless dialogbox incase the diskspace is less than 20GB. It
works well in the Release mode. But it throws an assertion error in Debug
mode. I read somewhere that it is not a right way to use Main windows handle
in worker threads. Could you please tell me how to go about it.?
I need to fix this asap.
Thanks