I have to write a TCP/IP client application in .NET. (The server is actually an embedded device, so not concerned about the server side of it.)
I am wondering, instead of using asynchronous socket client read/write calls to keep my main application responsive, why not just use a backgroundworker and use synchronous calls inside that background loop?
They would serve the same purpose, no, and easier to program and debug?
BTW, I am restricted to .NET 3.5 so cannot use the async/await calls, which from another thread here ( Async/await vs BackgroundWorker ) seems to be what everyone is suggesting to use instead.
Based the many helpful comments below, I realize that should have been a little more detailed in my OP above.
The embedded device is a Digi WiFi Module ( http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/point-multipoint-rfmodules/xbee-wi-fi#overview )
I am NOT sending and receiving at the same time. The embedded device is connected one of our data acquisition systems. The DAQ receives a command and sends out a reponse - ONLY ONE command/response at a time.
I send a command to the embedded device. I then wait for the response. If I get a response I process it and then send the next command. If I do not get a response within x seconds, then I send the same command again. If I do not get a reponse even after n tries, then I assume the connection is broken (ok to do it this way? Then show an error message and stop? close socket connection and reopen and try again a few times?)
So it is ok if my backgroundworker thread blocks while receiving/sending. It is either sending or receiving, not both.