WorkerThreadProc has to be static otherwise you cannot pass it as a pointer to a function. A static method is exactly the same as a normal function but a member function works on an instance of a class. If you were able to pass it, it would be a pointer to a method and you would also have to pass the instance to the object in question because that is what a member really needs.
Bottom line, you have to make it static just because of the nature of AfxBeginThread.
If you need to delegate something to the instance you have to pass a parameter to the static method with the instance and then cast it back to the original class.
class CThreadDlg:public CDialog
{
protected:
UINT WorkerThreadProc();
public:
static UINT WorkerThreadProcStatic( LPVOID Param );
};
UINT CThreadDlg::WorkerThreadProc(){
MessageBox("Am in Thread Function and have instance","",MB_OK);
return 0;
}
UINT CThreadDlg::WorkerThreadProcStatic(LPVOID Param)
{
CThreadDlg* dlg = (CThreadDlg*)Param;
dlg->WorkerThreadProc();
}
void CThreadDlg::OnBnClickedOk()
{
AfxBeginThread( WorkerThreadProcStatic,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
MessageBox("Thread started","",MB_OK);
}