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

Home Posts Topics Members FAQ

closing a TcpConnection

hello,

I have a class (I call them MyConnection), which establishes a
connection using a TcpClient.
After this connection is established I get the Network stream from the
TcpClient and create a StreamReader and a Streamwriter "on" it!
Then I start a new Thread which reads from the Streamreader.

When I close the connection using TcpClient.Close();
And try to reuse the class by call the constructor again
myConnection = new MyConnection();
It doesn't work correctly?

How to close such a class correctly?
How to safely close the thread?

(excuse my english <- I'm from germany)

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
2 1863
Take a look at Dispose and finalize, here :
http://msdn.microsoft.com/library/de...mberstopic.asp

Sometimes close leaves the unmanaged resources "hung".

HTH,

Denis
"Dirk Reske" <_f*******@gmx.net> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
hello,

I have a class (I call them MyConnection), which establishes a
connection using a TcpClient.
After this connection is established I get the Network stream from the
TcpClient and create a StreamReader and a Streamwriter "on" it!
Then I start a new Thread which reads from the Streamreader.

When I close the connection using TcpClient.Close();
And try to reuse the class by call the constructor again
myConnection = new MyConnection();
It doesn't work correctly?

How to close such a class correctly?
How to safely close the thread?

(excuse my english <- I'm from germany)

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
Hi,

Post your constructor code.

How it does not work correctly?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dirk Reske" <_f*******@gmx.net> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
hello,

I have a class (I call them MyConnection), which establishes a
connection using a TcpClient.
After this connection is established I get the Network stream from the
TcpClient and create a StreamReader and a Streamwriter "on" it!
Then I start a new Thread which reads from the Streamreader.

When I close the connection using TcpClient.Close();
And try to reuse the class by call the constructor again
myConnection = new MyConnection();
It doesn't work correctly?

How to close such a class correctly?
How to safely close the thread?

(excuse my english <- I'm from germany)

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #3

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

Similar topics

1
by: Daniel | last post by:
the api call in vb.net looks like this Dim WithEvents mobjSocketClient As TCPConnection how to do this in C# (particularly the equivilant of WithEvents)
6
by: Al the programmer | last post by:
I want to catch the Closing event for my form. I created a test windows app using the wizard. I then create the Closing event by clicking the lightning bolt on the properties pane. The code is...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
1
by: Daniel | last post by:
the api call in vb.net looks like this Dim WithEvents mobjSocketClient As TCPConnection how to do this in C# (particularly the equivilant of WithEvents)
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
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
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...
0
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 ...

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.