Multithreading

MFC prend en charge les threads de travail et les threads gui (threads avec boucles de message). Voir https://msdn.microsoft.com/en-us/library/975t8ks0.aspx pour plus de documentation.

Exemple simple de thread de travail AfxBeginThread

Cet exemple montre un appel de AfxBeginThread qui démarre le thread de travail et un exemple de procédure de thread de travail pour ce thread.

// example simple thread procedure.
UINT __cdecl threadProc(LPVOID rawInput)
{
    // convert it to the correct data type. It's common to pass entire structures this way.
    int* input = (int*)rawInput;
    // TODO: Add your worker code...
    MessageBox(0,"Inside thread!",0,0);
    // avoid memory leak.
    delete input;
    return 0;
}
// ...
// somewhere that gets called when you want to start the thread...
int* input = new int;
*input = 9001;
AfxBeginThread(threadProc, input);
// after this, the message box should appear, and the rest of your code should continue 
// running.