none
关于线程间访问控件出现线程间操作无效,MessageBox为什么不会? RRS feed

答案

  • MessageBox是直接调用线程安全的windows API,不过你也不应该在工作线程显示这个窗口,会影响界面线程的焦点和活动窗口。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年6月29日 16:29
    版主

全部回复

  • MessageBox是直接调用线程安全的windows API,不过你也不应该在工作线程显示这个窗口,会影响界面线程的焦点和活动窗口。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年6月29日 16:29
    版主
  • 还有几个问题,

    1.既然是线程安全的windows API,为什么winform下的控件做不到这些?

    2.如果我要自己模拟个跟MessageBox一样的静态类,我就不应该继承Form,而必须使用Windows API进行构造线程安全的用户控件吗?

    3.为什么winform下的控件会造成线程安全的问题?

    2011年6月30日 14:50
  • 因为Windows Forms使用了TLS。如果你自己写的话,不要用依赖于TLS的类库。

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年6月30日 15:08
    版主