473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tell original Thread that new thread is done working?

I have a ListView in my application. It is populated on Form_Load thru a For
Each Loop and in the loop I add a Button to a cell on each row. This works
perfect.

I have an update button beside the ListView that, when clicked, starts a
new thread that reads thru a bunch of files and emails.. and when this is
done it repopulates the ListView.
But when it's called from this thread it crashes on adding the buttons do
not ask me why but the error is... "Controls created on one thread cannot be
parented to a control on a different thread."

So what I want to do is to NOT repopulate the ListView from this thread but
instead tell the original Thread to populated the ListView.

How can this be done or can I get around this some other way?

/
Lars Netzel
Nov 21 '05 #1
2 1235
you need a delegate function that runs in the form's thread, because you
cannot access a control from any thread other than the form's thread.

you then need to Invoke that delegate function from your worker thread.

its a bit tricky to master. these pages contain examples:
http://www.devcity.net/Articles/160/4/article.aspx
http://www.vbforums.com/showthread.php?t=363002

"Lars Netzel" <ui****@adf.s e> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
I have a ListView in my application. It is populated on Form_Load thru a
For Each Loop and in the loop I add a Button to a cell on each row. This
works perfect.

I have an update button beside the ListView that, when clicked, starts a
new thread that reads thru a bunch of files and emails.. and when this is
done it repopulates the ListView.
But when it's called from this thread it crashes on adding the buttons do
not ask me why but the error is... "Controls created on one thread cannot
be parented to a control on a different thread."

So what I want to do is to NOT repopulate the ListView from this thread
but instead tell the original Thread to populated the ListView.

How can this be done or can I get around this some other way?

/
Lars Netzel

Nov 21 '05 #2
Thank you.. I did thry that Invoke stuff.. that took away the crash I got..
but I'm still not sure if the thread is acting the way it shoudl cause
something is taking a long time that shouldn't-- oh well... I have no
crash... thank you

/lars

"Wicksy" <wi*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
you need a delegate function that runs in the form's thread, because you
cannot access a control from any thread other than the form's thread.

you then need to Invoke that delegate function from your worker thread.

its a bit tricky to master. these pages contain examples:
http://www.devcity.net/Articles/160/4/article.aspx
http://www.vbforums.com/showthread.php?t=363002

"Lars Netzel" <ui****@adf.s e> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
I have a ListView in my application. It is populated on Form_Load thru a
For Each Loop and in the loop I add a Button to a cell on each row. This
works perfect.

I have an update button beside the ListView that, when clicked, starts a
new thread that reads thru a bunch of files and emails.. and when this is
done it repopulates the ListView.
But when it's called from this thread it crashes on adding the buttons do
not ask me why but the error is... "Controls created on one thread cannot
be parented to a control on a different thread."

So what I want to do is to NOT repopulate the ListView from this thread
but instead tell the original Thread to populated the ListView.

How can this be done or can I get around this some other way?

/
Lars Netzel


Nov 21 '05 #3

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

Similar topics

303
17491
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which...
6
1727
by: David Allison | last post by:
Relationship problem ~ How to tell Owner his db is crap. His db was made in 1999 - 12 tables - none normalised - none with relationships.(YES REALLY) He only knows about inputing data - 22,000 records. How does one solve this type of Relationship ? -- Dave Allison ~ Scotland
2
1400
by: roni | last post by:
hi. i have applcation in net. in that application i have 3 threads. 1- main thread with message loop and form 2. thread with message loop and form 3. thread with message loop and form now ,i want thread 2 to tell thread 3 to exceute method in async way :
5
12973
by: Steven Thomas | last post by:
I have an application that creates mutliple thread like this: My code: > ------------------------------------------------------------------------- > Private Sub StartGPReportServer() > Try > 'Dim some variables........ > While IsRunning > ' LOOP THROUGH THE AVAILABLE THREADS > ...
3
1820
by: brian_harris | last post by:
I am tring to start a thread where I am passing info into thread. According to MS documentation I must do this by creating a class for that thread. I have done this but am getting a compiler error. The error is: c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(104): error C2475: 'ThreadWithState::readerThread' :...
3
1454
by: ctbfalcon | last post by:
So I have a progress bar that I would like to be diplayed as the program is working on adding a network printer. I want to do this because while the program is "thinking" the user is not sure if it is locked up or actually doing somthing. So I wanted to start another thread (form3) with the progress bar on top of the main form (form1). So...
9
18007
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form will almost always lead to the user opening a certain child window that's fairly resource intensive to load. Is it possible to load this form in a...
10
5042
by: Paul E Collins | last post by:
I want to fill an ImageList with bitmaps for a ListView from another thread, because it's a time-consuming process. I expect the ListViewItems' images to "load" one by one, as in a Web browser. I wrote the following code, but the form freezes up while CreateTileBitmaps is running, just as if I'd done it on the main thread. How can I add...
0
7615
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...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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...
1
5514
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...
0
5219
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.