开发者

Thread Synchronization and Thread Pausing\Resuming

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, th开发者_StackOverflow中文版en when second complete and the after resume the first one.

Please help, I am lost in threads.


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.


TCP is a bi-directionnal protocol. Even if you receive a file, you are sending acknowledgment all along. This means TCP works within a context : there is one receiver end, and one sender end.

You should not mix role within an instance. Use 2 different instances. They can work in parallel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜