473,394 Members | 1,817 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,394 software developers and data experts.

Threading ListBox and TreeView

Tom
Hi Everybod

I can add some thing to ListBox from a new thread but can not add a node into a TreeView and get an exception that says you need marshaling. What is the difference and why

Thanks in advance for any reply
Tom
Nov 15 '05 #1
2 10031
Hi Tom,

You shouldn't touch UI controls from within non UI thread.
Rather use Control.Invoke method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Tom" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
Hi Everybody

I can add some thing to ListBox from a new thread but can not add a node into a TreeView and get an exception that says you need marshaling. What is
the difference and why?
Thanks in advance for any reply,
Tom

Nov 15 '05 #2
Hi Tom,

As Miha pointed out, Windows forms controls are inherently not
thread safe. So in effect, there may not be any guarantee that the
next time the list box is updated, it might succeed. In fact, we might
get the same marshalling error seen for the TreeView.
So if you mainpulate these controls from any thread
other then the main thread that owns the control,
it is safer to use Control.Invoke() to update the control.
For example:
To add an item to the ListBox from another thread:

delegate void AddToListBoxDelegate(String item);

// ...

if(listBox.InvokeRequired)
{
// Called from another thread ...
_listBox.Invoke(new AddToListBoxDelegate(Add,
new Object[] {"Hello"}));
}
else
{
_listBox.Items.Add("Hello");
}

// ...
public void Add(String item)
{
_listBox.Items.Add(item);
}

Regards,
Aravind C

"Tom" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
Hi Everybody

I can add some thing to ListBox from a new thread but can not add a node into a TreeView and get an exception that says you need marshaling. What is
the difference and why?
Thanks in advance for any reply,
Tom

Nov 15 '05 #3

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

Similar topics

2
by: W.G. Rowland | last post by:
In some ways I'm starting to miss the simpler days of VB5.. Anyway, here's my problem. I'm trying to build a MSDE client using an MDI Parent/Child interface. Enough of the tasks the program...
11
by: Timo Kunze | last post by:
Hi! If you move the mouse over an item that's part of a treeview and wider than the treeview, a tooltip showing the full item text will be displayed. I try to do this for ListBoxes and...
4
by: Roger | last post by:
I have a function that is currently wrapped up in a Class so I can pass a variable to it. This function is going to be threaded out and I would like the class function to be able to update a...
7
by: Paul Bromley | last post by:
How can I use this please - I need 2 columns. I have been having difficulty finding info on this and the 2005 Treeview control today. Many thanks for any links or info, Paul Bromley
1
by: Alex D. | last post by:
hey guys I found what is causing the problems with my treeview in Firefox...the answer is: treeview+dropdwonlist in the same page dont work! try this simple code and see for yourselves. you can do...
4
by: Domac | last post by:
Hi, Can I change color for each row in listbox??? Thanx!
4
by: hooksie2 | last post by:
Hi, I am trying to use FileSystemWatcher to watch a log file which is written to via a 3rd party app and display the log in listbox on a form. The FileSystemWatch seems to work okay but I get...
5
by: Chris | last post by:
Hi everyone- So I have this treeview control that I'm populating from a dataset. Problem is, there are 10 tables in the dataset (I didn't set the database up, for the record). So I'm having to...
3
by: veenna | last post by:
hi, I have to display some data in TreeView Control and the Treeview control should be inside a LIst box. Is It Possible to use TreeView inside a list box OR can i list details in list box...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...

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.