How can we create thread in MFC framework?
Answers were Sorted based on User's Feedback
MFC support two type of thread : Worker Thread & UI thread.
There is an overloaded function called AfxBeginThread()for
creating threads in MFC but at APT level you can't
differentaite.
At implementation level you can find the difference:-
For worker thread:
AfxBeginThread(); It takes 6 parameters, first param as
address of thread controlling function(must),2nd as
parameter passed to threadfn(must),3'rd thread priority
level(optional), 4'th as stack size(Optional),5'th as
create_flag(optional),6'th security class(optional)etc.
For UI(User Interface) thread:
Derive a class from CWinThread;
class CMyThread:public CWinThread
{
.....
.....
.....
}
Override the InitInstance() function in this class.
Then use the function
AfxBeginThread()and pass the parameter in RUNTIME_CLASS
macro in this func.
i.e. AfxBeginThread(RUNTIME_CLASS(CMyThread));
It takes 5 parameters ...rest of last four params are same
as worker thread which are optional.
So in this you can create the Worker and User Interface
threads.
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / jianhua wang
For worker thread:
AfxBeginThread();
for user interface thread:
Derive a class from CWinThread;
AfxBeginThread(); (Another version)
//if the thread is created in a suspended state, you must call
CWinThread::ResumeThread();
| Is This Answer Correct ? | 3 Yes | 1 No |
Explain in sort What is CTargetObject?
how does conditionally close the Dialog Box ?
if i modified data in 1 view how does the other view knows
1)How to change a text of a button in runtime?
What is stack size in win32 program?
How to convert a CString variable to char* or LPTSTR?
What is the difference between the Encapsulation and Abstraction
25 Answers HCL, Invensys, TCS, Wipro,
What are the special requirements for dialog box resources used in a form view?
What is a critical section and how is it implemented?
Differ GetMessage, PostMessage & PeakMessage?
If application hangs while SendMessage is waiting for the result, how you handle it?
what are the feauters of CObject