Hmm.., ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK) fixes the problem, but what was wrong with EndDialog?! Stack trace: USER32! 77d562cf() CDialog::EndDialog(int) ReadDeviceThread(void *) _threadstart(void *) KERNEL32!7c80b50b() ---------------------------- ProgressDialog.cpp ---------------------------- // ProgressDialog.cpp : implementation file // #include "stdafx.h" #include "monitor.h" #include "ProgressDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ProgressDialog dialog ProgressDialog::ProgressDialog(CWnd* pParent /*=NULL*/) : CDialog(ProgressDialog::IDD, pParent) { //{{AFX_DATA_INIT(ProgressDialog) m_text = _T(""); //}}AFX_DATA_INIT } void ProgressDialog::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CDialog::OnFinalRelease(); } void ProgressDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ProgressDialog) DDX_Control(pDX, IDC_MPROGRESS, m_bar); DDX_Text(pDX, IDC_MPROGTEXT, m_text); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ProgressDialog, CDialog) //{{AFX_MSG_MAP(ProgressDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ProgressDialog message handlers int ProgressDialog::DoModal(char *txt) { m_text = txt; //m_bar.SetRange(0,100); //m_bar.SetPos(0); return CDialog::DoModal(); } void ProgressDialog::SetText(char *txt) { m_text = txt; UpdateData(FALSE); } void ProgressDialog::SetPos(int pos) { m_bar.SetPos(pos); } void ProgressDialog::OnCancel() { // TODO: Add extra cleanup here StopAcc = 0; CancelProgressModal = 1; Sleep(4); // a little delay to stop a collision CDialog::OnCancel(); } void ProgressDialog::SetRange(int min, int max) { m_bar.SetRange(min, max); } ---------------------------- ProgressDialog.h ---------------------------- #if !defined(AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_) #define AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_ #include "stdafx.h" #include "resource.h" #if _MSC_VER >= 1000 #pragma once #endi