Response to: Making mfc call a function continuously until success is returned.
Revision 1
Using an infinite (or even time consuming) loop is a bad idea. It will block your application with probably high CPU load. The best solution would be posting a user defined message to the dialog from a thread that waits for the attach event.
A simpler method is using a timer inside your dialog that polls the attach state:
class CMyDialog : public CMyDialog
{
protected:
bool m_bAttached;
UINT m_nTimer;
};
CMyDialog::CMyDialog()
{
m_bAttached = false;
m_nTimer = 0;
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_nTimer = SetTimer(1, TIME_OUT_VALUE, NULL);
return TRUE;
}
void CMyDialog::OnTimer(UINT nIDEvent)
{
if (m_nTimer && attach())
{
m_bAttached = true;
StopTimer();
}
CDialog::OnTimer(nIDEvent);
}
void CMyDialog::StopTimer()
{
if (m_nTimer)
{
KillTimer(m_nTimer);
m_nTimer = 0;
}
}
Posted 20-Sep-12 21:39pm
by
Jochen Arndt.