Re: Critical section-Updating the Dialog from Workerthread
On 30 Mrz., 13:38, Mikel <mikel.l...@gmail.com> wrote:
On 30 mar, 13:10, Lucress Carol <incognito...@gmx.de> wrote:
On 30 Mrz., 03:38, scott...@mvps.org wrote:
In your original post you said you wanted to compute something in the=
thread 40 times and display the result in the GUI. So after the thread com=
putes it should post the result in the wParam.
In your most recent post you now have the result (newvalue) shown as =
a parameter, but you still don't use it! Instead, you are setting newvalue =
to something else, then displaying the something else. The task of the OnSe=
ndCalculatedValue function should be to display the newvalue that it receiv=
es from the thread.
Is there a possibility to calculate in the Thread procedure the
operation rand()*m_Slider.GetPos()
Yes. Whenever the slider changes you get OnHScroll. Have the main thr=
ead OnHScroll store the GetPos() value in an int variable. The thread can r=
ead the int value without synchronization.
How can the thread read that int value? should the gui post a
PostThreadMessage to the thread with the value??
How about something like this:
class CWorkerThreadMgr
{
// Your stuff
protected:
int m_pos;
public:
void SetPos(int pos) { m_pos = pos; }
int GetPos() { return m_pos; }
}
void CStartCalculationDlg::OnHScroll(UINT nSBCode, UINT nPos,
CScrollBar* pScrollBar)
{
// Whatever you have now
m_WorkerThreadMgr.SetPos(m_Slider.GetPos());
}
static UINT WINAPI ThreadProc( LPVOID lptest )
{
CWorkerThreadMgr* pCalculateMgr = reinterpret_cast<
CWorkerThreadMgr*>( lptest);
for( UINT uCount = 0; uCount < 40; uCount++ ){
int value = pCalculateMgr->rand() *pCalculateMgr.GetPos=
();
PostMessage(pCalculateMgr-> m_hWnd, WM_SENDCALCULATED_VAL=
UE,
value, 0);
}
}
LRESULT CStartCalculationDlg::OnSendCalculatedValue( WPARAM v,
LPARAM )
{
m_Calculation.Format(_T("%d"), (int)v);
SetDlgItemText(IDC_CALCULATION, m_Calculation);
return 1;
}- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
Thank you for the hint. I'm going to try it out ...