473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to operate list control in a worker thread

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!
Nov 17 '05 #1
3 1358
zhaoyandong wrote:
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.
Nov 17 '05 #2
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.
"Mihajlo Cvetanović" wrote:
zhaoyandong wrote:
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.

Nov 17 '05 #3
zhaoyandong wrote:
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*)
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?
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.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: User N | last post by:
I have a log class with static methods that grab and release a mutex as required. The log class is designed to be called from both GUI and thread pool threads, and dump output to a logfile and a...
6
by: Brian Henry | last post by:
I was wondering how you guys would handle filling a list view with something like 10,000 items which each have 10 sub items on them... there has to be major speed issues with that right? Yet,...
6
by: Valerie Hough | last post by:
I'm not entirely sure what the difference is between these two approaches. In order to avoid reentrant code, I was using Control.BeginInvoke in my UI to cause an asynchronous activity to be done...
5
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't...
2
by: RobKinney1 | last post by:
Please, can someone please tell us how to call a webbrowser control (navigate2 or navigate) from a worker thread safely? I have stepped through tutorials on the web about delegated calls and...
12
by: joey.powell | last post by:
Hello, I have an app that uses a tab control with several tab pages. Sometimes some of the processing initiated on one of the tab pages gets busy doing stuff that is farmed out to worker...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
7
by: Ben Voigt [C++ MVP] | last post by:
As much as the CLR team assures us that it's ok to fire-and-forget Control.BeginInvoke, it seems it isn't. Maybe this is a bug. See for example: the comments in...
1
by: schnandr | last post by:
Hi, I have a user control which contains ListView. I copy all ListViewItems into a separate List<ListViewItemcalled unfilteredItems. I am using a BackgroundWorker to filter the ListView. When...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.