473,466 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

2 threads, 1 GUI, 1 tcp client... 1 bug

Okay:
I have a GUI program that initializes a TcpClient and a Form. From withing
the form I create a TextBox and init the client. Then I run a
System.Threading.Timer with a method that checks if the TcpClient has
available data, and if it does, it tries to send that data as text to the
TextBox. But, of course I get an Exception - Illegal cross-thread operation -
because I am not allowed to access the Control (TextBox) from a thread it
wasn't created in.
How do I do this? I understand I'm supposed to create a delegate etc., but
I've never done such a thing and I'n confused. If someone could explain it
better, preferably with a code example, I'll be very thankful.
Just for emphasis - I want to change a Form TextBox from a thread it wasn't
created on.

Thanks!
Nov 17 '05 #1
3 1731
yoav <yo*****@hotmail.com> wrote:
Okay:
I have a GUI program that initializes a TcpClient and a Form. From withing
the form I create a TextBox and init the client. Then I run a
System.Threading.Timer with a method that checks if the TcpClient has
available data, and if it does, it tries to send that data as text to the
TextBox. But, of course I get an Exception - Illegal cross-thread operation -
because I am not allowed to access the Control (TextBox) from a thread it
wasn't created in.
How do I do this? I understand I'm supposed to create a delegate etc., but
I've never done such a thing and I'n confused. If someone could explain it
better, preferably with a code example, I'll be very thankful.
Just for emphasis - I want to change a Form TextBox from a thread it wasn't
created on.


See http://www.pobox.com/~skeet/csharp/winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2


"Jon Skeet [C# MVP]" wrote:
yoav <yo*****@hotmail.com> wrote:
Okay:
I have a GUI program that initializes a TcpClient and a Form. From withing
the form I create a TextBox and init the client. Then I run a
System.Threading.Timer with a method that checks if the TcpClient has
available data, and if it does, it tries to send that data as text to the
TextBox. But, of course I get an Exception - Illegal cross-thread operation -
because I am not allowed to access the Control (TextBox) from a thread it
wasn't created in.
How do I do this? I understand I'm supposed to create a delegate etc., but
I've never done such a thing and I'n confused. If someone could explain it
better, preferably with a code example, I'll be very thankful.
Just for emphasis - I want to change a Form TextBox from a thread it wasn't
created on.


See http://www.pobox.com/~skeet/csharp/winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


A very helpful site Jon has! Solved my problems and cofusions. Thanks alot
John!
the url, however, seems to be different (at least for me):
http://www.yoda.arachsys.com/csharp/...winforms.shtml

Good day.
Nov 17 '05 #3
yoav <yo*****@hotmail.com> wrote:
A very helpful site Jon has! Solved my problems and cofusions. Thanks alot
John!
My pleasure - glad it helped.
the url, however, seems to be different (at least for me):
http://www.yoda.arachsys.com/csharp/...winforms.shtml


They're the same URL really - pobox.com is a redirection service, so
the pobox.com URL should work forever, even if I change web host.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

8
by: Eric B. | last post by:
Hi, I'm running into a slight programming issue here that I am hoping someone can help me with. I am developping a web-based PHP application, which means I have to consider multiple threads of...
5
by: Tzach | last post by:
I'm developing a simple Java client that runs over a CORBA server. The main client thread is waiting for notification from this server. On each notification, The client creates a new thread...
5
by: Ralph Sluiters | last post by:
Hi, i've got a small problem with my python-script. It is a cgi-script, which is called regulary (e.g. every 5 minutes) and returns a xml-data-structure. This script calls a very slow function,...
0
by: Gavin Williams | last post by:
I am working on a multi-threaded server for a Windows 2000 system and since "fork" doesn't work that great in a Win32 environment, I am trying to use use the "threads" module instead. When a...
5
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or...
6
by: Quiet Man | last post by:
Hi all, I'm designing a fairly simple service that will run on W2K/SP4 and W2K3 servers. It's job is to be a very specialized database server that listens on a given IP address / TCP port and...
10
by: Mark Denardo | last post by:
Hi, I have multi-threaded application that requires one particular thread (Non-Form based) to receive data from other threads. I know how to pass control to Form Threads, but I believe there's no...
11
by: Teja | last post by:
I have an application which uses COM 's Dispatch to create a COM based object. Now I need to upgrade the application to a threaded one. But its giving an error that COM and threads wont go...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
2
by: nxs | last post by:
in the following program, I am trying to create M threads, each of which open a file called filexxxxin . for exmaple 4th thread will open file file0003.in. When I run the program, it open the...
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
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,...
1
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...
0
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.