Re: Updating Controls from a Thread Causes Access Violation
From: Jim Howard (jnhtx_at_spamcop.net)
Date: 11/10/04
- Next message: Jo: "Re: CAsyncSocket behaving multithreaded"
- Previous message: Chiap Zap: "Re: Random string"
- In reply to: Brad McMillan: "Updating Controls from a Thread Causes Access Violation"
- Next in thread: Jeff F: "Re: Updating Controls from a Thread Causes Access Violation"
- Reply: Jeff F: "Re: Updating Controls from a Thread Causes Access Violation"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Nov 2004 13:38:49 -0600
Pass into your thread a pointer to the GUI's window object (either a window
handle or a CWnd*) . Use this pointer to send a message from the thread to
the dialog window to tell it to update. Direct messing about with the GUI
from a worker thread is "Considered Harmful".
Jim H
"Brad McMillan" <mcmillan@viselect.com> wrote in message
news:4191d942.176097375@dslnews.netwiz.net...
> Hi:
>
> I have a VC++ 6.0 Dialog based application where I'm trying to update
> a static control from a thread.
>
> My main dialog is:
>
> CMyDlg* myDlg;
>
> I create the thread with the following code:
>
> myDlg = this;
> void myThread(void *ch);
> _beginthread( myThread, 1000, (void*)(ch));
>
> Then, I am updating my static control from within the thread with:
>
> myDlg->myVar = "Test";
> myDlg->OnUpdateControls();
>
> where myVar is a CString variable associated with my static control.
>
> The method OnUpdateControls is:
>
> void CMyDlg::OnUpdateControls()
> {
> UpdateData(FALSE);
> }
>
> The problem is that when I run this under Debug I get an access
> violation when UpdateData(FALSE) is executed.
>
> Can anyone tell me why I'm getting an access violation here? Or, is
> there a better way of updating my static control from within the
> thread?
>
> TIA,
> Brad McMillan
>
>
>
- Next message: Jo: "Re: CAsyncSocket behaving multithreaded"
- Previous message: Chiap Zap: "Re: Random string"
- In reply to: Brad McMillan: "Updating Controls from a Thread Causes Access Violation"
- Next in thread: Jeff F: "Re: Updating Controls from a Thread Causes Access Violation"
- Reply: Jeff F: "Re: Updating Controls from a Thread Causes Access Violation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|