Click here to Skip to main content
15,885,881 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: OnFileOpen crashing [solved] Pin
_Flaviu5-Apr-13 2:18
_Flaviu5-Apr-13 2:18 
GeneralRe: OnFileOpen crashing [solved] Pin
David Crow5-Apr-13 3:14
David Crow5-Apr-13 3:14 
GeneralRe: OnFileOpen crashing [solved] Pin
Richard MacCutchan5-Apr-13 3:35
mveRichard MacCutchan5-Apr-13 3:35 
GeneralRe: OnFileOpen crashing [solved] Pin
SoMad5-Apr-13 7:39
professionalSoMad5-Apr-13 7:39 
QuestionWindows Service Controler & CAsyncSocket Pin
Member 33971274-Apr-13 20:43
Member 33971274-Apr-13 20:43 
AnswerRe: Windows Service Controler & CAsyncSocket Pin
Jochen Arndt4-Apr-13 22:55
professionalJochen Arndt4-Apr-13 22:55 
GeneralRe: Windows Service Controler & CAsyncSocket Pin
Member 33971275-Apr-13 1:46
Member 33971275-Apr-13 1:46 
GeneralRe: Windows Service Controler & CAsyncSocket Pin
Jochen Arndt5-Apr-13 2:18
professionalJochen Arndt5-Apr-13 2:18 
You are creating a user-interface thread. With socket operations worker threads are usual.

Also, why did you retry to create the thread if the first call fails? This makes no sense.

If the thread creation is done by your main thread, it will be blocked by calling WaitForSingleObject() until the thread terminates.

The skeleton for using a worker thread would look like this:

class CMyClass // optional : public CObject
{
public:
    void StartThread();
protected:
    bool m_bKill;
    CWinThread *m_pThread;
    static UINT ThreadFunc(LPVOID pParam);
};

void CMyClass::StartThread()
{	
    m_pThread = AfxBeginThread(ThreadFunc, this, THREAD_PRIORITY_NORMAL,
        0, CREATE_SUSPENDED);
    // When m_pThread is deleted by this class (e.g. when using a StopThread() function)
//  m_pThread->m_bAutoDelete = FALSE;
    m_pThread->ResumeThread();
}

UINT CMyClass::ThreadFunc(LPVOID pParam)
{
    CMyClass* pThis = reinterpret_cast<CMyClass*>(pParam);
    bool bKill = false;
    while (!bKill)
    {
        // Call WaitForMultipleObjects() here to:
        //  Check for kill event: Break
        //  Check for I/O event: Handle event
        //  Check for timeout: Break or handle it in some way
        // If not using a kill event
        if (pThis->m_bKill)
            break;
    }
    return 0;
}

AnswerRe: Windows Service Controler & CAsyncSocket Pin
Member 33971275-Apr-13 3:27
Member 33971275-Apr-13 3:27 
QuestionTimer not working properly. Pin
Le@rner4-Apr-13 20:25
Le@rner4-Apr-13 20:25 
AnswerRe: Timer not working properly. Pin
Captain Price4-Apr-13 21:24
professionalCaptain Price4-Apr-13 21:24 
QuestionRe: Timer not working properly. Pin
CPallini4-Apr-13 23:03
mveCPallini4-Apr-13 23:03 
AnswerRe: Timer not working properly. Pin
David Crow5-Apr-13 3:17
David Crow5-Apr-13 3:17 
GeneralRe: Timer not working properly. Pin
Le@rner5-Apr-13 19:34
Le@rner5-Apr-13 19:34 
QuestionRe: Timer not working properly. Pin
Kenneth Haugland6-Apr-13 3:06
mvaKenneth Haugland6-Apr-13 3:06 
AnswerRe: Timer not working properly. Pin
Le@rner10-Apr-13 22:07
Le@rner10-Apr-13 22:07 
QuestionRetaining selection on a ListCtrl Item Pin
Donguy19764-Apr-13 14:21
Donguy19764-Apr-13 14:21 
AnswerRe: Retaining selection on a ListCtrl Item Pin
SoMad4-Apr-13 15:07
professionalSoMad4-Apr-13 15:07 
GeneralRe: Retaining selection on a ListCtrl Item Pin
Donguy19765-Apr-13 9:27
Donguy19765-Apr-13 9:27 
GeneralRe: Retaining selection on a ListCtrl Item Pin
SoMad5-Apr-13 10:47
professionalSoMad5-Apr-13 10:47 
GeneralRe: Retaining selection on a ListCtrl Item Pin
Donguy19765-Apr-13 11:32
Donguy19765-Apr-13 11:32 
GeneralRe: Retaining selection on a ListCtrl Item Pin
SoMad5-Apr-13 21:39
professionalSoMad5-Apr-13 21:39 
QuestionHow to resize a dialog? Pin
Donguy19764-Apr-13 14:18
Donguy19764-Apr-13 14:18 
AnswerRe: How to resize a dialog? Pin
Garth J Lancaster4-Apr-13 15:24
professionalGarth J Lancaster4-Apr-13 15:24 
AnswerRe: How to resize a dialog? Pin
David Crow5-Apr-13 3:19
David Crow5-Apr-13 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.