|
-
Nov 21st, 2006, 07:37 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] Small problem with thread
I've found an open source user control which is effectively a clone (almost) of the VB6 Winsock Control. Yes I know theres many out but this is the only one I can get working - sort of. Find it here:
http://www.codeproject.com/vb/net/winsockdotnet.asp
You remember the VB6 winsock events? Connected, DataArrival etc etc....well this .Net control has those too, and here's the problem:
When I place some simple code within the event such as:
VB Code:
Private Sub Winsock1_Disconnected(ByVal sender As Winsock_Control.Winsock) Handles Winsock1.Disconnected
Label1.Text = "dc"
'when the connection is disconnected, set the text of the label
End Sub
It throws an exception:
Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.
Surely I should be able to access my controls from the events, otherwise the events here, are pretty much useless??
Thanks, any help is much appreciated as always
-
Nov 21st, 2006, 09:31 PM
#2
Re: [2005] Small problem with thread
Yes and no.... I think what's happening is that the "winsocks" are being spun off into a thread separate from the main app. As a result, the event fires off in that thread, rather than your own, which is why you can't access Label1.
I'm not sure how to fix it though. I'm guessing that the callback will need to be setup differently.
-tg
-
Nov 22nd, 2006, 10:25 AM
#3
Thread Starter
Frenzied Member
Re: [2005] Small problem with thread
Hi tg, yes thats exactly the problem, the user control creates another thread(s). I have found a newer version of the control, which is for 2005 and is thread safe, so no problems with it.
If anyone wants it, its here:
http://www.codeproject.com/useritems/winsock2005.asp
Cheers mate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|