0
votes

I need to write a .NET 2.0 C# class library to wrap some calls to a serial port.

I already know that using DataReceived event of the SerialPort object is (probably) the best way to read data from the port just when they are available for read.

Nevertheless, calls to my class library should be sync and then I can't use DataReceived that is async.

Is there a suggested develop pattern to do a thing like that?

Thanks, Manuel

1
why do you need sync access to class libraries? Is it UI access problem ?Tigran
This, "...calls to my class library should be sync and then I can't use DataReceived that is async." needs clarification.dbasnett
No, it isn't UI access problem. I need to create a class (say Wapper) with methods to wrap the calls to the serial port and I'd like to avoid using Read() into a while or similar. Each of these methods should be sync, but inside of them I need to read/write asyncrously to the serial port.Flea777

1 Answers

0
votes

Just use a while loop while waiting for your data.