Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

How to operate list control in a worker thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zhaoyandong - 20 Jun 2005 13:35 GMT
I have two threads, one UI thread, the other, the worker thread, which is
responsible for keeping on search things and post the found results to a list
control on the UI.

My leader doesn't allow me to use MFC.

So I have to use SendMessage(LVM_XXX, hListCtrl) in the worker thread, I
guess.

But I failed, there is nothing displaying in the list control in the UI
dialog.

Any people can tell me what's the reason? Thanks very much!
Mihajlo Cvetanović - 20 Jun 2005 14:15 GMT
> So I have to use SendMessage(LVM_XXX, hListCtrl) in the worker thread, I
> guess.
>
> But I failed, there is nothing displaying in the list control in the UI
> dialog.

Use PostMessage(hListCtrlParent, UWM_UPDATE_LIST, wParam, lParam) in the
worker thread, and SendMessage(hListCtrl, LVM_...) in the event handler
of user window message UWM_UPDATE_LIST. This might not solve your
problem, but it's the right thing to do.

If wParam and lParam should contain some structs or buffers (like char*)
then create them in worker thread, and delete them in event handler.
zhaoyandong - 21 Jun 2005 05:08 GMT
Thank you very much, Mr Cvetanović .

Your answer is what I really need.

You mean UWM_UPDATE_LIST is a user-defined message, actually listcontrol and
the parent of listcontrol own the same message queue.

I also planned to send the WM_NOTIFY(LVN_INSERTITEM) message to the parent
dialog, but it is also not right solution.

About
---------------
If wParam and lParam should contain some structs or buffers (like char*)
then create them in worker thread, and delete them in event handler.
---------------
This is also what I'm thinking. If I don't create/new the struct or buffer
in the worker thread, but  instead, use the stack, and post the address of
the struct as lParam or wParam to the UI. I'm afraid this will cause UI to
lose some results.
Am I right?

Also one of my colleague says, continuously "new" and "delete" will cause
many memory fragments. Is he right? If he is right, How should I avoid this?

Thank you.

> > So I have to use SendMessage(LVM_XXX, hListCtrl) in the worker thread, I
> > guess.
[quoted text clipped - 9 lines]
> If wParam and lParam should contain some structs or buffers (like char*)
> then create them in worker thread, and delete them in event handler.
Mihajlo Cvetanović - 21 Jun 2005 12:08 GMT
> You mean UWM_UPDATE_LIST is a user-defined message, actually listcontrol and
> the parent of listcontrol own the same message queue.

Yes, that's correct (in this simple case).

> ---------------
> If wParam and lParam should contain some structs or buffers (like char*)
[quoted text clipped - 5 lines]
> lose some results.
> Am I right?

Yes, you're right, if you want to PostMessage to pass structures around
then you must use the heap.

> Also one of my colleague says, continuously "new" and "delete" will cause
> many memory fragments. Is he right? If he is right, How should I avoid this?

If you post structs or classes then they are all of the same size, so
there's no fragmentation. But if you post char* (or char* inside the
struct) AND those buffers are of the various sizes (between 1 byte and 1
megabyte) then there might be fragmentations. However, you shouldn't
think about performances so early, the chances are you wont feel any
slowdown.

So the answer is that he could be right, but that could be irrelevant.

Fragmentation could be avoided if you use buffers of the same size, or
if you "recycle" old buffers, but I repeat you shouldn't worry about
that right now.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.