473,698 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1376
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(hLi stCtrlParent, UWM_UPDATE_LIST , wParam, lParam) in the
worker thread, and SendMessage(hLi stCtrl, 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_I NSERTITEM) 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(hLi stCtrlParent, UWM_UPDATE_LIST , wParam, lParam) in the
worker thread, and SendMessage(hLi stCtrl, 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
4663
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 RichEditBox. To give you some idea of the approach I took... private static RichTextBox rtb; private delegate void RtbAppendTextHandler(string output); private static RtbAppendTextHandler RtbAppendText; Log.Init(RichTextBox richTextBox,...
6
9044
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, applications like outlook and such can retrieve and display tens of thousands of emails with virtually no performance hit at all... how would we go about getting a .NET listview to get similar performance? when I try to do what I said above, it takes...
6
15153
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 on the UI's message loop. I began to get System.ExecutionEngineException errors so (on the theory of do something different if what you're doing isn't working) I switched to using delegate.BeginInvoke with the appropriate EndInvoke and the problem...
5
3542
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 only one worker thread running at any time (if a new worker thread start has been requested, any running worker thread results will be invalid). I'm using the below method to invoke a new worker thread, but when stress testing this I'm sometimes...
2
7271
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 invoke methods but they don't make much sense to me... and all of them seemed overly done just to change a single control value. Right now I am getting an error that says: "Current thread must be set to single thread apartment (STA) mode before OLE...
12
2315
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 threads. I have to be able to prevent the tab page from changing (prevent users selecting other tabs) while this is going on. I already have a variable to track the status of this (i.e. "bool IsBusy"), but I cannot figure out now to "freeze" the tab...
8
2982
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 the big changes I want to make is event-driven code (rather than the linear flow I had in Java). I have spent a week or so searching Google, talking to a couple of programming friends, and just chewing on it in my brain. I think I have an ok handle...
7
5660
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 http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx I was encountering a bug that disappeared when debugging. Not when a debugger is attached, mind you, but when I placed a breakpoint near the code. Adding Trace.WriteLine statements showed that the failing code was...
1
4793
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 I access this list in the DoWork Handler I am getting an InvalidOperationException that the List was not created by this thread. Is there a way to solve this problem?
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.