An application that must take action in response to received data might need to
read each byte as soon as it arrives at the port. In that case, use the DataReceived
event for fast response and set ReceivedBytesThreshold to 1.
Managing Ports and Transfers in .NET
203
When sending data, the application should prevent or minimize timeouts and
prevent buffer overflows. An application can perform write operations in a separate
thread to avoid blocking the application??™s thread. This section shows strategies
for accomplishing these tasks.
8 1
The likelihood of a timeout increases when an application transfers large quantities
of data, uses a slow bit rate, or uses flow control.
When a write operation times out, any data that was waiting to transmit in that
operation is lost. Data queued to the port in subsequent write operations
remains in the buffer. Setting WriteTimeout to InfiniteTimeout ensures that
write operations never time out, but a write operation could wait forever if the
remote computer hangs and doesn??™t allow the data to transmit. Applications
that need to send large blocks of data can use multiple write operations to send
the data in chunks with generous but finite timeouts. Writing data in smaller
chunks also helps prevent buffer overflows.
6
Using the standard Windows drivers, a write operation to a physical COM port
will block until the UART has transmitted all of the data or a timeout has
occurred.
Pages:
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236