Chỉ cập nhật Hình chữ nhật của Khách hàng

lập trình


Xin chào,

Tôi đang làm việc trên một ứng dụng MFC đa luồng cần vẽ biểu đồ trên điều khiển hình ảnh. Mọi thứ dường như

hoạt động tốt ngoại trừ thực tế là điều khiển hình ảnh không vẽ lại khi gọi hàm Không hợp lệ cho hình ảnh

điều khiển. Toàn bộ cửa sổ được vẽ lại và xảy ra nhấp nháy nếu tôi gọi Không hợp lệ trên hộp thoại. Mọi gợi ý về nơi tôi

tôi đang đi sai hướng? Tôi đã thử điều này nhưng nó không giúp được gì: http://computer-programming-forum.com/82-mfc/1d8b6d604dd7c393.htm

Mã số:

C++
DWORD WINAPI CDlg::WorkerThread(LPVOID lpVoid)
{
CDlg* appPtr = (CDlg*)lpVoid;
CStatic* pStatic = (CStatic*)appPtr->GetDlgItem(IDC_GRAPH_WINDOW);

while(true)
{
// Plotting graph
// Requires Update
appPtr->UpdatePoints(i);
pStatic->PostMessage(WM_PAINT);
}
}

Giải pháp 1

Tôi nghĩ vấn đề là do sự truy cập của GUI từ luồng công việc. Hãy xem bài viết này để biết cách làm đúng: Sử dụng chủ đề công nhân[^]

Worker threads and the GUI II: Don't touch the GUI

That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc.

Why?

Because you can get into a serious deadlock situation. A classic example was posted on one of the discussion boards, and it described something that had happened to me last year. The situation is this: you start a thread, and then decide to wait for the thread to complete. Meanwhile, the thread does something apparently innocuous, such as add something to a list box, or, in the example that was posted, calls FindWindow. In both cases, the process came to a screeching halt, as all threads deadlocked.

Giải pháp 3

http://Www.hotboat.com/frm/member.php?u=12894

コメント

タイトルとURLをコピーしました