Hi,
Lets say I have a sensor class manager (SensorServer).
Inside that class I have an event that helps me receive status changes regarding the sensor:
public event OnSensorStatus OnSensorStatusEvent;
In my view model (EventsMgr.cs), I create an instance of SensorServer and register for this event:
Server = new SensorServer();
Server.OnSensorStatusEvent += Srv_OnSensorStatusEvent;
Server.StartServer();
Whenever an event occurs, the code goes into the following method:
private void Srv_OnSensorStatusEvent(SensorStatus sensorStatus)
{
}
Inside the event, the SensorStatus contains an ID with which I can obtain the event-related sensor by calling the following asynchronous method inside SensorServer:
public async Task<Sensor> GetSensorById(Guid id)
{
await Task.Delay(_random.Next(_maxDelayForGetSensor));
return _sensors.FirstOrDefault(sensor => sensor.Id == id);
}
My question is this:
The events happen every 200 milliseconds or so and I wanted to know what is the best way to operate it? My goal is to call GetSensorById every time the event happens (in a separate thread) and when a reply comes back access the callback with the response.
I need each call to be handled individually.
I cannot change anything inside the SensorServer.cs.
What I have tried:
.............................................