The default
is one byte. If you set the property to a larger number, the DataReceived event
is likely to be raised less often and each event will likely have more data to process.
Setting a threshold greater than 1 can prevent the receiving computer from seeing
some or all of the received data. For example, assume that Received-
BytesThreshold in the receiving computer is set to 4 and the transmitting
computer sends 3 bytes. The buffer holds fewer bytes than the threshold, so the
DataReceived event isn??™t raised. Unless the transmitting computer sends
another byte or the receiving computer polls the receive buffer, the application
doesn??™t know the bytes arrived.
An application that has finished communicating with a port should close the
port and free its resources to allow other applications to use the port if needed.
The Close method closes the connection to the port and clears the receive and
transmit buffers. The Dispose method calls the Close method and releases all
resources used by the component, making it possible to reopen a port quickly
after closing it.
Attempting to close a port that doesn??™t exist causes a NullReferenceException.
Attempting to close a port that isn??™t open causes an InvalidOperationException.
To avoid these exceptions, check to see that the port exists and is open before
closing it.
Chapter 9
162
When a port is transmitting, closing the port or clearing the transmit buffer can
crash Windows.
Pages:
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199