I am writing a program-emulator of instrument operation (several at once). Data exchange "occurs" conditionally over the RS-485 network, i.e. The program connects to the network and adds "virtual devices" to the network. It is implemented like this: 1. There is an object "data bus". Essentially a container of objects of the same type. Receiving from one object Send makes distribution to all others. 2. Bus objects. They may have different functionalities, but they implement one basic interface with the Receive function (data reception from the bus). There are two types of bus objects: "virtual device" - (based on the received data, it does the calculation and "sends" the result to the "bus"), "data source" (for example, the object opens a COM port, or TCP, or some other, and sends the data to the "bus", and from the bus back to the port). There is no limit on the number of any type of bus objects (i.e. there may be 10 COM ports).
So here. Everything works fine. But I would like to put all this in a separate thread. What it is for - all objects "initiate" events (TNotifyEvent), for example OnDataReceive, OnChanged, etc. Processing (visual reflection of the accompanying information in the program window) of these events may take a long time (critical for emulation). Because of what the master device (the real device on the RS-485 bus) "loses" virtual devices.
Fully implementation can not imagine (and therefore implement, not knowing exactly what to do). It looks like this: - Create an object "bus" - Create-Add the necessary objects to the "bus" - Start the stream (some method of the bus "RunEmulation"), start the "data sources" objects. - All data from the "sources" are sent to the stream of emulation, is sent to the recipients, processing. - In the case of "initiation" of an event, the bus sends PostMessage with the necessary information and the bus already calls the main thread OnDataReceive, OnChanged, etc. (then the messages will be queued, and user processing will not affect the work of the emulation flow)
Something like this. Can someone solve a similar problem or just have thoughts on the right approach to implementation