CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2003
    Posts
    91

    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);
    }

  2. #2
    Join Date
    Aug 2004
    Location
    INDIA
    Posts
    260

    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 ), 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.
    If you feel this post is useful,
    Rate this Post by clicking right top corner (Rate this Post)
    Santhosh

    ***Add strength to your country - Interesting Poll
    ***

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    Join Date
    Jan 2005
    Location
    China
    Posts
    4

    Re: open window from UI Thread interupts main thread???

    use just one ui thread

  5. #5
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    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

  6. #6
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured