Use the event but if you are using net 4.5 or newer you may use async, await:
Asynchronous Programming with Async and Await (C# and Visual Basic)[
^] and
Simple Async Await Example for Asynchronous Programming | Stephen Haunts { Coding in the Trenches }[
^].
You do this by calling ReadAsync on the BaseStream object.
This is from working code. You should be able to see what is happening.
try
{
while ((drb_args.NumBytes = await _serialPortNet.BaseStream.ReadAsync(drb_args.BytesOut, 0, BufferLen, cancellationToken)) != 0)
{
cancellationToken.ThrowIfCancellationRequested();
if ((drb_args.NumBytes > 0))
{
}
}
}
catch (Exception ex)
{
if (ex.GetType().Name == "TaskCanceledException")
{
stop();
}
}
As for actual performance this will depend on other factors as already pointed out.