Re: Updating Controls from a Thread Causes Access Violation
From: Jeff F (not_at_anywhere.com)
Date: 11/10/04
- Next message: Geo: "Re: Help with a dialog-based application"
- Previous message: Jo: "Re: CAsyncSocket behaving multithreaded"
- In reply to: Jim Howard: "Re: Updating Controls from a Thread Causes Access Violation"
- Next in thread: Scott McPhillips [MVP]: "Re: Updating Controls from a Thread Causes Access Violation"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Nov 2004 14:51:11 -0500
"Jim Howard" <jnhtx@spamcop.net> wrote in message
news:%23Kqvqz1xEHA.1188@tk2msftngp13.phx.gbl...
> 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
I assume you meant PostMessage not SendMessage.
Jeff F
> 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: Geo: "Re: Help with a dialog-based application"
- Previous message: Jo: "Re: CAsyncSocket behaving multithreaded"
- In reply to: Jim Howard: "Re: Updating Controls from a Thread Causes Access Violation"
- Next in thread: Scott McPhillips [MVP]: "Re: Updating Controls from a Thread Causes Access Violation"
- Messages sorted by: [ date ] [ thread ]