Multithread with MFC 4.2

How can I implement a multithread functionality in my program in order to start a ca. 2 minutes longing procedure without interrupting users work?
Please show me what I have to initialize, where do I have to place the code, how I call the routine and what have to be done after the procedure has finished?

{//---------- THREAD_PRIORITY_BELOW_NORMAL - thus the user //interface is not affected by calculation. You can also use
//THREAD_PRIORITY_NORMAL
AfxBeginThread( ::CalcProc, this, THREAD_PRIORITY_BELOW_NORMAL );
//-- Updates user interface and variables to show that // calculation starts
......
}

When the function CalcProc() exits the calculation is finished.
You should be careful whiel accessing variables and user interface from CalcProc(), because it executes from contenst of another thread. There are problems with syncronisation and thread local storage. Thus I prefer to post command message to the dialog to announce finish of calculation, instead of taking some action inside of CalcProc().
I can give you more advises if you ask specific questions.
Yours, Igor.

Not the solution you were looking for? Getting a personalized solution is easy.

Thanks for it. After I tried it I immediatly was shocked that I wasn't aware to ask how I can throw out data by that thread:
This thread is created as a worker thread but also this thread has to report the process of his work. I do this by inserting text into a dialog box with an CEdit field in it. But this time it returns the failure "Access violation". therefore my question: how can I share this dialog box which is an element of my derived CMDIFrameWnd ?
Hope you can manage this!

Dear trouvain,
I am sorry I didn't your comment - do you have dialog or class derived from CMDIFrameWnd, where the CEdit field.
IN general the multithreading with MFC is tricky, you cannot pass freely the CWnd pointer from one thread to another. IN general hte safe way is to update the internal data structures ( your data ) and post user-defined notification messages to the main window.

In my example you can access member variables of CMyDlg and you can change the test in the controls:
UINT CMyDlg::CalcProc()

Hi Igor,
Unfortunately are my surroundings different:
The worker thread is called from a message handler of CMDIMyFrame. My reporting routine is implemented as a dialog which is a member of CMDIMyFrame. Since there existing more than only one functionality I have a global report function. This function gets the dialog pointer via calling AfxGetMainWindow. But every time I try to get the dialog pointer by referencing ((CMDIMyFrame*)AfxGetMainWindow())->m_dlgReport->SetWindowText(...);
I get a access violation failure.
Is there at all a way to access data respective functions of another thread?
In case there is please explain me for a last time how to do it.
Many thanks in advance.
Marcel