Click here to Skip to main content
15,914,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: DirectShow Pin
Rajkumar R19-Feb-08 18:20
Rajkumar R19-Feb-08 18:20 
GeneralRe: DirectShow Pin
Chandrasekharan P19-Feb-08 18:27
Chandrasekharan P19-Feb-08 18:27 
AnswerRe: DirectShow Pin
Rajkumar R19-Feb-08 18:38
Rajkumar R19-Feb-08 18:38 
Generalgaussion function in c++ [modified] Pin
gentleguy19-Feb-08 16:15
gentleguy19-Feb-08 16:15 
GeneralRe: gaussion function in c++ Pin
CPallini19-Feb-08 22:54
mveCPallini19-Feb-08 22:54 
GeneralRe: gaussion function in c++ [modified] Pin
gentleguy20-Feb-08 0:31
gentleguy20-Feb-08 0:31 
QuestionRe: gaussion function in c++ Pin
CPallini20-Feb-08 4:26
mveCPallini20-Feb-08 4:26 
GeneralUI Thread question (noob) Pin
Maximilien19-Feb-08 13:47
Maximilien19-Feb-08 13:47 
I take full responsability on my "noobness" concerning threads.

I have been reading a lot of Newcomer's comments and tips (http://www.flounder.com[^]) and a lot of other places, books, and I still got a few question.

If I create a UI thread like this (in a simple dialog based application (in the OnInitDialog) ) :

// m_pMyThread is derived from CWinThread.
m_pMyThread = new MyThread(this);
m_pMyThread->CreateThread(CREATE_SUSPENDED);
m_pMyThread->m_bAutoDelete = false;
m_pMyThread->ResumeThread();



And in my thread class, OnPlay and OnStop and thread messages called from my UI (with registered messages), the PostMessageW in the loop is to update a CStatic in the dialog:

	ON_REGISTERED_THREAD_MESSAGE(WM_PLAY_THREAD_MESSAGE, OnPlay)
	ON_REGISTERED_THREAD_MESSAGE(WM_STOP_THREAD_MESSAGE, OnStop)

void MyThread::OnPlay(WPARAM wParam, LPARAM lparam)
{
	m_bRunning = true;
	int i = 0;
	while( m_bRunning)
	{
		m_pParent->PostMessageW( WM_THREAD_PLAYING_MESSAGE, (WPARAM) i, 0 );
		Sleep(500);
		i++;
	}
	TRACE("MyThread::OnPlay\n");
}

void MyThread::OnStop(WPARAM wParam, LPARAM lparam)
{
	TRACE("MyThread::OnStop\n");
	m_bRunning = false;
}


This (above) obviously does not work since the loop in OnPlay is "blocking" the thread messaging. If I do not loop in OnPlay, the OnStop message is handled properly.

I also tried this, and it does not work either:

m_pMyThread->PostThreadMessage(WM_QUIT, 0, 0);



So, What is the way to to stop the loop from my UI ? I tried adding a PeekMessage/TranslateMessage/DispatchMessage check in my loop to see if it would catch the message.
I cannot send a message to the thread.


Is modifying the m_bRunning with a direct call the preferred way ? like :
m_pMyThread->m_bRunning = false;


Thanks for any info tips and hints.

Max.

Maximilien Lincourt
Your Head A Splode - Strong Bad

GeneralRe: UI Thread question (noob) Pin
Mark Salsbery19-Feb-08 14:45
Mark Salsbery19-Feb-08 14:45 
GeneralRe: UI Thread question (noob) Pin
Maximilien19-Feb-08 15:11
Maximilien19-Feb-08 15:11 
QuestionHow to start ? built app to communication through USB port Pin
quangpk19-Feb-08 13:12
quangpk19-Feb-08 13:12 
AnswerRe: How to start ? built app to communication through USB port Pin
Maxwell Chen19-Feb-08 15:57
Maxwell Chen19-Feb-08 15:57 
QuestionAny buttons styles to get a CButton to look like a toolbar button? Pin
jeffb4219-Feb-08 11:19
jeffb4219-Feb-08 11:19 
GeneralRe: Any buttons styles to get a CButton to look like a toolbar button? Pin
Maxwell Chen19-Feb-08 16:50
Maxwell Chen19-Feb-08 16:50 
GeneralSingle Processor Multithreaded Application!!!!!!! Does it Help????????????????? [modified] Pin
swarup19-Feb-08 10:05
swarup19-Feb-08 10:05 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
Maximilien19-Feb-08 10:24
Maximilien19-Feb-08 10:24 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
swarup19-Feb-08 10:53
swarup19-Feb-08 10:53 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
Dave Kreskowiak21-Feb-08 9:35
mveDave Kreskowiak21-Feb-08 9:35 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
led mike19-Feb-08 10:54
led mike19-Feb-08 10:54 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
swarup19-Feb-08 11:08
swarup19-Feb-08 11:08 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
led mike19-Feb-08 11:31
led mike19-Feb-08 11:31 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
swarup19-Feb-08 12:20
swarup19-Feb-08 12:20 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
led mike19-Feb-08 12:24
led mike19-Feb-08 12:24 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
David Crow19-Feb-08 17:04
David Crow19-Feb-08 17:04 
GeneralRe: Single Processor Multithreaded Application!!!!!!! Does it Help????????????????? Pin
Waldermort19-Feb-08 20:09
Waldermort19-Feb-08 20:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.