Click to See Complete Forum and Search --> : MFC C++ 2005 Multithreading Help


nightlite
May 2nd, 2011, 10:28 PM
I am a newbie in MFC C++ and I just want to ask if anyone knows where can I find a sample code application or could any one share a code of an application of Multithreading in MFC C++ 2005..

thanks in advance..

VictorN
May 3rd, 2011, 02:53 AM
Using Worker threads (http://www.flounder.com/workerthreads.htm)
Using User-Interface Threads (http://www.flounder.com/uithreads.htm)
and the serial communications example which uses worker and UI threads: Serial Port I/O (http://www.flounder.com/serial.htm)

nightlite
May 3rd, 2011, 05:05 AM
..thank you very much VictorN..
i'll try that right away..
..thank you again.. :)

Igor Vartanov
May 4th, 2011, 01:25 AM
BTW, just a side note: using MFC does not oblige you to use MFC thread classes and functions exceptionally. It happens all the time in my practice that doing threads in plain Win API looks more natural to me. But this is very personal matter (of habits, preferences, skills, project requirements, coding standards, etc.), and you may find MFC stuff more appropriate/convenient for yourself.

nightlite
May 4th, 2011, 02:07 AM
..thank you Igor,
its just that my boss wanted us to learn and code applications with multithreading and synchronization using MFC applications. I'll try using Win app next time :). Thank you again..

alanjhd08
May 4th, 2011, 07:02 AM
Hi Igor,

I've noticed this on flounder.com:
_beginthread(), _beginthreadex(), or CreateThread() in an MFC program (http://www.flounder.com/badprogram.htm#beginthread)

Is that right, and if so do you need some special approach when using the Win API for threads under MFC?

VictorN
May 4th, 2011, 07:16 AM
Well there is a lot of discussion about it in the Web...
For example:
http://www.codeguru.com/forum/showthread.php?t=371305
http://www.codeguru.com/forum/showthread.php?t=433100
http://www.microsoft.com/msj/0799/win32/win320799.aspx

Igor Vartanov
May 4th, 2011, 07:59 AM
Victor, thank you for the collection of the links. In fact talking about WinAPI threads I meant _beginthreadex and CreateThread in contrast to using AfxBeginThread. But regarding specific problem of a choice between _beginthreadex and CreateThread I'd say _beginthreadex is always appears more preferable, of course unless you're absolutely sure you know what you do with CreateThread. :)

VictorN
May 4th, 2011, 08:04 AM
Igor, I agree!
Although I prefer using MFC CWinThread with AfxBeginThread for both worker and UI thread types. ;)

Igor Vartanov
May 4th, 2011, 08:04 AM
Is that right, and if so do you need some special approach when using the Win API for threads under MFC?In case you use CRT somewhere in thread, directly or indirectly, _beginthreadex is the choice. In case you're not sure if you do, _beginthreadex again is the choice. :) And only if you're absolutely sure you don't (i.e. you use some third party runtime or bare WinAPI), CreateThread is an option.

Igor Vartanov
May 4th, 2011, 08:08 AM
Although I prefer using MFC CWinThread with AfxBeginThread for both worker and UI thread types. ;)Yep, exactly what I meant. Habits, preferences and other stuff... :)