CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    17

    help on control update from a thread

    hi all,

    following is a code snippet of my program having vc6 mfc sdi & formview as basic characteristics.

    void CScada_thrdsView:sp_cnt()
    {
    while (!exit_thrd)
    {while(!nw_cnt) ;
    sprintf(cstring,"%d",count);
    m_val.InsertString((count-1),cstring);
    UpdateData(FALSE);
    ` nw_cnt = 0;
    }
    }
    a screen shot of the situation obtained on execution is attatched with this post.

    from debugging i gather that this error is being caused due to the updatedata statement.

    the function dsp_cnt is in form view but is being called from the worker thread.

    i request for help in sorting out this error.

    thnx
    ashwani
    Attached Images Attached Images

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: help on control update from a thread

    The simple guideline to avoid this is not to call GUI code from your worker thread. Do your work in a worker thread and post a message to the window telling it to update itself. You can pass the required information from the worker thread to the GUI using the WPARAM and LPARAM of the message, but the problem is that you basically don't know in what order the messages will be handled. So most of the time, it's better to push the information to a synchronized queue and use the message only as a notification that the GUI needs to be updated.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Apr 2010
    Posts
    17

    Re: help on control update from a thread

    D Drmmr,

    thnx for the guidance.

    ashwani

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