Sto scrivendo un'applicazione di acquisizione dati. Mi chiedo se dovrei utilizzare un evento più abbonati o più eventi più abbonati. Sono preoccupato per le prestazioni. Inoltre, potrei migliorare le prestazioni scaricando gli abbonati su un thread diverso?
Ecco un esempio di ciò che intendo per più eventi Più abbonati.
public delegate void EventChannelUpdated(object sender, EventArgsChannelUpdated e);
public class EventArgsChannelUpdated : EventArgs
{
public chCell chCell;
}
public delegate void EventLimitExceeded(object sender, EventArgsLimitExceeded args);
public class EventArgsLimitExceeded : EventArgs
{
}
class Example
{
public List<Channel> AllChannels;
}
public class Saver_allChannels
{
private Example example;
public event EventChannelUpdated eventChannelUpdated;
public void DataAdded()
{
//** this part is pseudo code as I have simplified some of the hwObjs structure
for (int i = 0; i < hwObjs.Count; i++)
{
example.ListOfchannels[i].addSamples(hwObjs[i].Reading);
}
}
}
public class Channel
{
public List<chCell> column { get; set; }
public string label { get; set; }
public event EventChannelUpdated eventChannelUpdated;
public double multipler { get; set; }
public void addSamples(double unScaledValue)
{
chCell temp = new chCell() {channel = this, scaledValue = unScaledValue*multipler};
column.Add(temp);
eventChannelUpdated(this,new EventArgsChannelUpdated(){chCell = temp});
}
}
public class chCell
{
public double scaledValue { get; set; }
public Channel channel { get; set; } //** parent Channel List
}
public class Monitor
{
public double Limit;
public event EventLimitExceeded eventLimitExceed;
public void Handle_EventChannelUpdated(object sender, EventArgsChannelUpdated args)
{
if (args.chCell.scaledValue > Limit)
{
eventLimitExceed(this, new EventArgsLimitExceeded());
}
}
}
Ecco un esempio di cosa intendo per un evento più abbonati
public delegate void EventChannelUpdated(object sender, EventArgsChannelsUpdated e);
public class EventArgsChannelsUpdated : EventArgs
{
public List<chCell> RowOfchCells;
}
public delegate void EventLimitExceeded(object sender, EventArgsLimitExceeded args);
public class EventArgsLimitExceeded : EventArgs
{
}
class Example
{
public List<Channel> ListOfchannels;
}
public class Saver_allChannels
{
Example example;
public event EventChannelUpdated eventChannelUpdated;
public void DataAdded()
{
List<chCell> LastRow = new List<chCell>();
//** this part is pseudo code as I have simplified some of the hwObjs structure
for (int i = 0; i < hwObjs.Count; i++)
{
example.ListOfchannels[i].addSamples(hwObjs[i].Reading);
LastRow.Add(new chCell() {channel = example.ListOfchannels[i], Value = hwObjs[i].Reading});
}
eventChannelUpdated(this, new EventArgsChannelsUpdated() { RowOfchCells = LastRow });
}
}
public class Channel
{
public List<chCell> column { get; set; }
public string label { get; set; }
public double multipler { get; set; }
public void addSamples(double unScaledValue)
{
chCell temp = new chCell() {channel = this, scaledValue = unScaledValue*multipler};
column.Add(temp);
}
}
public class chCell
{
public double scaledValue { get; set; }
public Channel channel { get; set; } //** parent Channel List
}
public class Monitor
{
public double Limit;
public Channel subbedChannel;
public event EventLimitExceeded eventLimitExceed;
public void Handle_EventChannelUpdated(object sender, EventArgsChannelsUpdated args)
{
double value = (args.RowOfchCells.FirstOrDefault(x => x.channel == subbedChannel)).scaledValue;
//** do something with value
}
}