Re: List Control Thread Access
- From: "NoName" <NoName@xxxxxxxxxxxx>
- Date: Thu, 19 May 2005 14:23:41 -0500
First of all your thread is a worker thread, and can't process GUI stuff.
Second, and probably the reason your program is crashing is that MFC object
are not thread safe, which means that you can't simply pass a list control
object to another thread and expect it to work (the message pump from MFC is
not thread safe).
The correct way to solve your problem is to create a GUI thread, and post
messages back to the main thread (who owns the list control) and have it
update the list control.
Or you can simply pass the hWnd of the list control to the GUI thread, and
post messages to the list control to add items.
AliR.
"Phil" <spam@xxxxxxxxxxx> wrote in message
news:MPG.1cf6f2eefeb0dae0989791@xxxxxxxxxxxxxxxxxxxx
> I have a little problem trying to access a list control in a program
> from a thread.
>
> The main program is an MFC SDI app with a list control on the main view,
> then in the initialupdate I start a thread with the following code;
>
> (The thread is called via "AfxBeginThread(RunThread, this); ").
>
> UINT CProkNETView::RunThread(LPVOID p)
> {
> CProkNETView * me = (CProkNETView *)p;
> me->AutoUpdateThread();
> return 0;
> }
>
> void CProkNETView::AutoUpdateThread(void)
> {
> m_wndList.InsertItemEx(0,"text");
> }
>
>
> When "InsertItemEx" is called from the thread, the program crashes. When
> it is just called from a normal non threaded part of the program it
> works fine. Surely the "AutoUpdateThread" function should be able to
> access the list control fine, as it's still part of "CProkNETView" ?
>
> Am I missing something ?
>
>
>
> --
> Phil
>
.
- Follow-Ups:
- Re: List Control Thread Access
- From: Phil
- Re: List Control Thread Access
- References:
- List Control Thread Access
- From: Phil
- List Control Thread Access
- Prev by Date: Re: thread question
- Next by Date: Re: Please use wxWidgets
- Previous by thread: List Control Thread Access
- Next by thread: Re: List Control Thread Access
- Index(es):
Relevant Pages
|