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

thread error

When I add a control to a panel, I get this error :
"Controls created on one thread cannot be parented to a control on a
different thread."
Does anyone knows what I'm doing wrong ?
Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error
thx
Snuyt

Nov 20 '05 #1
7 1116
* Snuyt <sn**********@skynet.be> scripsit:
When I add a control to a panel, I get this error :

"Controls created on one thread cannot be parented to a control on a
different thread."

Does anyone knows what I'm doing wrong ?

Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error


Are you using multiple threads?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Herfried K. Wagner [MVP] wrote:
* Snuyt <sn**********@skynet.be> scripsit:
When I add a control to a panel, I get this error :

"Controls created on one thread cannot be parented to a control on a
different thread."

Does anyone knows what I'm doing wrong ?

Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error

Are you using multiple threads?


It 's a client - server program. Whenever the server sends a certain
message to the client, There is a new PictureBox() created and shown. So
no multiple threading

Snuyt

Nov 20 '05 #3
Cor
Hi Snuyt,

You did supply this, but what is the Panel?

Cor
Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error

Nov 20 '05 #4
Cor wrote:
Hi Snuyt,

You did supply this, but what is the Panel?

Cor

Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error



Panel is a Windows.Forms.Panel Control.

Nov 20 '05 #5
Cor
Hi Snuyt,

I will say it more clear, where is the Panel situated in your project?
Panel is a Windows.Forms.Panel Control.


Cor
Nov 20 '05 #6
client - server without multithreading...
is this possible?

i think you will need to check the Invoke method on Panel...

private sub doit()
Panel.Invoke(new MethodInvoker(AddressOf InvokeThisSub))
end sub

private sub InvokeThisSub()
Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p)
end sub
when server "says" to add the picture, call the doit sub

"Snuyt" <sn**********@skynet.be> wrote in message
news:40***********************@news.skynet.be...
Herfried K. Wagner [MVP] wrote:
* Snuyt <sn**********@skynet.be> scripsit:
When I add a control to a panel, I get this error :

"Controls created on one thread cannot be parented to a control on a
different thread."

Does anyone knows what I'm doing wrong ?

Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + k.getUniCode.ToString + ".bmp")
p.SetBounds(1, 2, 72, 96)
Panel.Controls.Add(p) <-- here comes the error

Are you using multiple threads?


It 's a client - server program. Whenever the server sends a certain
message to the client, There is a new PictureBox() created and shown. So
no multiple threading

Snuyt

Nov 20 '05 #7
I will create a more clearly view on my program:

CLIENT:
=======
Private Sub clientconnected_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Try
client = New TcpClient(ip, port)
client.GetStream.BeginRead(readBuffer,0,READ_BUFFE R_SIZE, _
AddressOf DoRead, Nothing)

Catch Ex As Exception
MsgBox("Cannot Connect", MsgBoxStyle.Exclamation, "Error")
Me.Close()
End Try
End Sub
Private Sub DoRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer
Dim strMessage As String

Try
BytesRead = client.GetStream.EndRead(ar)
If BytesRead < 1 Then
MarkAsDisconnected("No butes read")
Exit Sub
End If

' Convert the byte array the message was saved into, minus
' two for the Chr(13) and Chr(10)
strMessage = Encoding.ASCII.GetString(readBuffer,0,_
BytesRead - 2)

Catch e As Exception
MarkAsDisconnected(e.Message)
Exit Sub
End Try
ProcessCommands(strMessage)
Try
client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE,_
AddressOf DoRead, Nothing)
Catch e As Exception
MarkAsDisconnected(e.Message)
End Try
End Sub

' Process the command received from the server,
' and take appropriate action.
Private Sub ProcessCommands(ByVal strMessage As String)
Dim dataArray() As String

' Message parts are divided by "|" Break the string
' into an array accordingly.
dataArray = strMessage.Split(Chr(124))

' dataArray(0) is the command.
Select Case dataArray(0)
Case "IMG"
DRAW_AN_IMAGE(dataArray(1))
Case Else
End Select
End Sub
Private Sub DRAW_AN_IMAGE(ByVal data As String)
Dim p As New PictureBox()
p.Image = New Bitmap("pics/" + data + ".bmp")
p.SetBounds(1, 1, 72, 96)
Panel.Controls.Add(p)
p.BringToFront()
End Sub
The error occurs on the "Panel.Controls.Add(p)" line

Any solutions ?

Thanks

Nov 20 '05 #8

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

Similar topics

0
by: John Goerzen | last post by:
Hello, I am the author of OfflineIMAP, a program that currently is a heavy user of threads. For various reasons (see below), thread groups are something that is highly desirable for me in...
4
by: cedric | last post by:
hello, I encounter a problem using threads. I have a simple code to use a thread : cSurveillanceBorne = New clsThreadSurveillance _SurveillanceThread = New Thread(AddressOf...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
4
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
5
by: Brian | last post by:
I have an file based asp.net application the creates a thread to do some background printing. It works fine but when the application is deployed on a web server, the following error occurs in the...
0
by: sauce | last post by:
Hi, Hm this error has gotten me really frustrated....I wrote a cgi script implementing threads using the threading module, but ran into these errors from my web server: Exception in thread...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.