I'm developing ASP .Net core application to communicate with USB Serial device to read/write device information using binary serializer.
Moreover, I have created a common wrapper project to communicate with hardware using SerialPortStream and BinarySerializer. There is a method to accept the command from user and serialize and deserialize the command and finally return the output. Method name -IGenericMessagePacket GetMessageFromDevice(IGenericMessagePacket packet).
So as per requirement, I have to create a long running task to communicate with device in every 1sec to get current status of the device. In between, there is another method will be called by user to get another information from device.
Long running task and general function are trying to communicate with device. I'm getting irrelevant output when handling above scenarios. I used lock but it will make some problem.
can anyone suggest me how to solve this issue?