Using background threads for long processes in MFC: Background Thread 2

15 Apr 2003 11:52 mfc

We can solve the problem of the memory leak, and of the premature destructor call, by simply blocking until the thread is finished:

void CBgthreadDlg::OnBackgroundJoin()
    CWaitCursor wait;

    TaskThread *t = new TaskThread;

    // Wait for it to finish
    delete t;

This is, in effect, no better than any of our foreground thread examples, but it does get us a step closer to the ideal solution.

The source so far: