有一段代码,要从数据采集卡中读取大量数据,并显示在界面上,应该用worker线程,还是UI线程?

解决方案 »

  1.   

    当然是Worker线程,完成了发一个通知给UI要他更新
      

  2.   

    从CWinThread继承下来的线程就叫UI线程,与Work线程的最大区别就是UI线程有消息泵,可以处理线程消息。PostThreadMessage 发送线程消息
    ON_THREAD_MESSAGE 映射线程消息
      

  3.   

    我在worker线程中直接写:SetDlgText()来刷新界面的显示好不好?
      

  4.   

    晕,一楼在说什么啊?
    请参阅MSDN 
    There are two general types of threads that CWinThread supports: worker threads and user-interface threads. Worker threads have no message pump: for example, a thread that performs background calculations in a spreadsheet application. User-interface threads have a message pump and process messages received from the system. CWinApp and classes derived from it are examples of user-interface threads. Other user-interface threads can also be derived directly from CWinThread.
      

  5.   

    例子:UINT MyThread()  //worker thread
    {
       
        //从数据采集卡中读取数据:
        ReadDataFromHardware();
        //在界面edit中显示数据:
        SetDlgItem(IDC_EDIT1, sData);  //这句话放在工作线程中行不行?
        
    }
      

  6.   

    靠,当然不行
    SetDlgItem函数是CDialog的方法,怎么能调用呢?
    可以在Work线程创建时将Dialog的指针传给线程,再从线程中还原出来调用Dialog的方法,
    不过这种方法也不好。
      

  7.   

    ::SetDlgItemText(hDlg,IDC_VALUE_SET,str);
    hDlg唯控件所在窗口句柄,IDC_VALUE_SET唯控件ID,str為設置的字符串。在任何地方調用都可以。
      

  8.   

    USERINTERFACE。
    用来处理用户消息的。
      

  9.   

    有种常用模式:WORK线程用来读数据,放在一个缓冲区,
    然后UI线程或者主线程不必去管WORK线程如何,只管显示缓冲区的数据.
      

  10.   

    halfdream(哈欠) 的方法不错啊,用work线程读取数据放到一个缓冲区中,而用户线程用来取数据就可以了啊。