Communication in ASP.NET Core

2019-09-14 19:57发布

问题:

Situation:

I need to create some kind of controlling part of the communication over Modbus TCP/IP in my ASP.NET Core project.

Communication is working correctly with Modbus, but I need to read some Modbus addresses pernamently and I need to set them interval. I have such structure for this in db.

I have now singleton called CommunicationRepository, which is such controller for this protocol and have methods to read from the module, write to module, have structure for data from modules, etc. and create CommunicationRunners.

CommunicationRunner is something that can wait to elapse the interval and than fire delegate from CommunicationRepository - which then read specific Modbus address.

Problem: Now it is done by async, which is slowing down everything else - navigating throught the page, responses from web api, etc. Offcourse this problem is recognizable at small intervals (e.g. 10ms).

How can I make this more stable, non-bugging? Do I have to use threading? If, then how exactly?

I would appreciate some code samples.

Thank you and have a look at images.