Tuesday, January 5, 2010

Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on

This error comes when you tries to add items in list box (or any other control) in thread (or from the function which is being used by thread).

Below is solution:

Private Delegate Sub stringDelegate(ByVal s As String)
Private Sub AddItem(ByVal s As String)
If ListBox1.InvokeRequired Then
Dim sd As New stringDelegate(AddressOf AddItem)
Me.Invoke(sd, New Object() {s})
Else
ListBox1.Items.Add(s)
End If
End Sub


now just pass your value in "AddItem()" and it will be added in listbox.

Share This!


24 comments:

Anonymous said...

Keep posting stuff like this i really like it

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Hey everybody I found a new way to learn about internet marketing here. It just started tonight at Midnight.
Its brand new on the web..Untouched and ready to drive Millions to your website Instantly

Its pretty exciting wa to get people to your website and complete tutorials on how to do it.

Anonymous said...

Hi folks... I am brand new here but I can't wait to start having/getting several good chats along with you all! I just figured i would introduce myself to you all so hello!

Anonymous said...

Hi,

I just came across to dotnetacademy.blogspot.com from google and I find dotnetacademy.blogspot.com very interesting.
I wish, can make lot's of new friend here :)

Anonymous said...

Hello. And Bye.

Anonymous said...

Hi!,

I'm new here and came to dotnetacademy.blogspot.com from search engine.

I really think this site dotnetacademy.blogspot.com was great and nice to be here.

I'm work on health related work and i have a site which giving out info about [url=http://healthlifesource.com/health-care-information/mens-health]Health News Information[/url]

I love for being health and i do anything to get my health target :)

Healthy life will make your life more longer and your body will become more strong also by do a healthy life will make your face looking fresh.

I really hope everyone here as healthy as i am but if not then you should change your life style immediatly for your own benefits :)

Anonymous said...

I totally support that! Continue that way!

Anonymous said...

You were not mistaken, truly

Anonymous said...

Just found this forum. Hi!!

Anonymous said...

Hello,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at dotnetacademy.blogspot.com have a mirror or another source?


Thanks,
Jack

Anonymous said...

Is it possible to contact administration?
Hih you hear me??

Anonymous said...

For the great posts

I'll be back for sure.


!

Have a wonderful and new year...


[url=http://www.duracleanaustin.com]austin carpet cleaning[/url]

Anonymous said...

Hey everyone, cool message board I find It extremely helpful and it's helped me a great deal
I hope to be able to contribute and assist other people like this message board has helped me

_________________
[url=http://iphoneusers.com]blackra1n[/url]

Anonymous said...

15061.....18873

Anonymous said...

For the awesome posts

I'll be back in a bit.


Thanks!

Have a safe and clean new year...


[url=http://www.duracleanaustin.com]austin carpet cleaning[/url]

Anonymous said...

The show must go on.

Anonymous said...

Great post thanks

Anonymous said...

Delighted to come in contact with every individual at this site

Anonymous said...

Happy to reach all of you on this site

Anonymous said...

I am freshman at this site and as a consequence first off i chooses to say hi to folks

Anonymous said...

Hey im new here.

Im sam, how is everyone?

I look forwards to being a active memeber

Anonymous said...

This is a very interesting site. The content is very informative and I am so glad that I dropped by. Thanks!

______________________________
Virginia Beach Roofing

Powered By Blogger · Designed By Seo Blogger Templates