open window from UI Thread interupts main thread???
Hi Guys,
I have a window that is going to do visualization display just like winamp. I notice when winamps visualization plays the audio is never interupted by the visualization display.
I tried to do the same thing by creating a UI Thread and giving it the priority of THREAD_PRIORITY_LOWEST and then by creating my window in the initinstance function like show below.
Buy my music is still interupted by the visualization display in the window I created in my UI Thread!! Shouldn't my visualization window be separate from my main dialog? Why is my visualization window still interrupting the music from my main dialog?
Thanks,
Greg
Code:
bool CUIThread::StartThread()
{
if(m_pThread == NULL) {
CRuntimeClass* manager = RUNTIME_CLASS( CUIThread );
m_pThread = (CUIThread *) AfxBeginThread(manager, THREAD_PRIORITY_LOWEST, 0, CREATE_SUSPENDED, NULL);
}
;
m_pThread->ResumeThread();
return true;
}
BOOL CUIThread::InitInstance()
{
pVisWindow.Create(IDD_VISUALIZATION_WINDOW);
pVisWindow.ShowWindow(SW_SHOW);
}
Re: open window from UI Thread interupts main thread???
Usually any kind of application shall have only one UI thread (only one user will be sitting before the system :rolleyes: ), and n number of worker thread based on the requirement.
In your case you are trying to create one more UI thread, it is well known in MFC that your WinApp application object is already derived from CWinThread. theApp object is a UI thread object.
Better idea would be keep your dialog which showing animation in application UI thread and create one more work thread to play the music. Synchronize display animation and music (between UI and worker thread). Put all your logic in worker thread to play music.
Re: open window from UI Thread interupts main thread???
If you use DirectSound then the sound replay will already be on a seperate thread so you don't have to worry about it.
Darwen.
Re: open window from UI Thread interupts main thread???
Re: open window from UI Thread interupts main thread???
Quote:
Originally Posted by revg75
...Why is my visualization window still interrupting the music from my main dialog?
It might be caused by the way your visualizations are controlled by the music. For example, if your main music UI thread is using SendMessage to send messages to the visualization UI thread, then your main thread will pause until the visualization thread processes the message, which will not occur until after the main thread loses its timeslice, the viz thread gets a timeslice, and the main thread gets a new timeslice.
Note that SendMessage is often hidden by MFC function calls. For example, CWnd::GetWindowText (which you probably don't use but I'm only giving it as an example) works by sending a WM_GETTEXT message to the CWnd object's window. So, your code might look like it's not sending messages even though it actually is.
Maybe you could post some code showing inter-thread communication.
Mike
Re: open window from UI Thread interupts main thread???
You shouldn't be using MFC window access calls across threads anyway, if you are.
You should drop into Win32 for this...
Darwen.