외규장각 도서 환수 모금 캠페인

Search Results for 'Thread'

1 POSTS

  1. 2007.06.27 updatedata와 thread

updatedata와 thread

Posted 2007. 6. 27. 10:18, Filed under: Study/Computer Science
How to use "updatedata" in a thread ? Unconfirmed/Anonymous posting  penny15  6:46 12 Nov '03 
I am a beginer in MFC programmation, I would like to use UpdateDate in order to refresh my Cdialog windows in a thread function
Thank you for your help.
Re: How to use "updatedata" in a thread ?   Joseph M. Newcomer 17:04 16 Nov '03
(a) you can't. It is that simple. Not possible. It will simply crash your app. Which is what it is supposed to do! It cannot under any circumstancces be called from a thread.

(b) WHY???? UpdateData is one of the worst ideas to have hit the programming community (as my essay says). Not only is it impossible to use it from a thread, but even considering the use of it for any purpose is, in my estimation, a fundamental design mistake.

Read my essay on threads. Just send notices to the main GUI thread to update what you need to have updated, and do something sensible, like SetWindowText, to update it (note that even if you could get UpdateData to work, it would STILL be a mistake, since it could be updating a string value that is BEING CHANGED RIGHT NOW by the thread, so it can't work anyway! The threads absolutely, positively MUST NOT touch any window owned by the main GUI thread (PostMessage does not constitute a "touch")

Re: How to use "updatedata" in a thread ?   satoufe 16:25 8 Jun '04

Hello, i would know if you arrived to call UpdataData within a thread...I am trying but always i v got error message Debug assertion..


need your help..
-> 이게 바로 내가 겪었던 문제! 윈도우 핸들을 통째로 쓰레드로 넘겨서 거기서 updatedata()를 호출하고 다른 프로시저를 쭉 실행해 나갈려고했는데 안된다.

결국은 updateadata() 부분을 빼고 나머지 부분만 쓰레드에서 구현했음.
Re: How to use "updatedata" in a thread ?   Joseph M. Newcomer 23:23 8 Jun '04
The rule is very simple: DO NOT EVER TOUCH A WINDOW FROM A THREAD. PostMessage is touching the thread's queue, not the window to which the message is being sent, so that is safe. UpdateData would be insane. Personally, I think it is insane to ever use UpdateData at all, so the fact that it makes no sense from a thread is pretty irrelevant to me. Note also that you cannot call SetWindowText, AddString, or pretty much any other method of a window from a thread that does not own it.

Bottom line: UpdateData is guaranteed to fail if called from a thread. Do not even contemplate the possibility it being a useful function to call from a thread that does not own the dialog. Second rule: do not consider the possibility of creating a dialog that is owned by the thread. That just puts you back in the same fix.

If you have thought you saw this all work successfully, you have seen an illusion. The illusion will eventually fail completely and unexpectedly in a way guaranteed to maximize embarrassment, safety risks, or your customer's loss of faith in your product.
----
DO NOT EVER TOUCH A WINDOW FROM A THREAD

그런 거였구나. 이상한 debug assertion 나는거 피해가느라고 엄청 고생하다가 결국은 포기했는데.

출처 - http://www.codeproject.com
Response : ,


Recent Posts

Recent Comments

Recent Trackbacks

Total hit (Today , Yesterday )

Admin Write Post