views:

56

answers:

1

Hi, I am trying to send the files from local to FTP, for that I am locking the TCPClient before sending the file. And that file sending is doing in another thread. So that the main thread doesn't affected.

As when I try to use the locked TCPClient before Unlocking it, it hangs. So how should I proceed, so that at the same time I can send the file also receive the file.(Both function are in different thread but locks the same TCPClient object).

I am also thinking to pause the first thread and perform second one, then when second complete and the after resume the first one.

Please help, I am lost in threads.

+1  A: 

You shouldn't use the same TcpClient from different threads to do different things - it represents a single connection, so the data sent and received on the two different threads would interfere with each other. (Even if you're "sending" a file in one and "receiving" a file in the other, both will need to send and receive data.)

I suggest you use two different TcpClient instances.

Jon Skeet