By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Is TcpClient thread safe ?

P: n/a
I'm creating a TcpClient instance in an object which is created in a
thread.

I have a loop that goes about 6-7 cycles, creating the container object
in each cycle and each object contains a TcpClient instance.

If I run this loop without threading everything goes find. But if I do
it within the thread, invariable on of the threads will fail to
connect.

So, I was wondering whether TcpClient is safe to be used in this way ?

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

It doesn't matter whether TcpClient is thread safe or not unless you are actually accessing an instance of TcpClient on multiple
threads. It sounds like you are creating one TcpClient per thread from your description.

Anyway, the docs say that instance members are not guaranteed to be thread-safe.

TcpClient on MSDN:
http://msdn2.microsoft.com/en-us/library/1612451t.aspx

--
Dave Sexton

<cr************@hotmail.comwrote in message news:11**********************@m73g2000cwd.googlegr oups.com...
I'm creating a TcpClient instance in an object which is created in a
thread.

I have a loop that goes about 6-7 cycles, creating the container object
in each cycle and each object contains a TcpClient instance.

If I run this loop without threading everything goes find. But if I do
it within the thread, invariable on of the threads will fail to
connect.

So, I was wondering whether TcpClient is safe to be used in this way ?

Sep 25 '06 #2

P: n/a

Thanks a lot, Dave, that's exacty the one doubt I've ever had but never
seen it explained in a single paragraph like this :
It doesn't matter whether TcpClient is thread safe or not unless you are actually
accessing an instance of TcpClient on multiple threads. It sounds like you are
creating one TcpClient per thread from your description.
Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.