I have the following code which is designed to listen to a (usually local: 127.0.0.1:8080) xml file and deserialize it into a class object.
private void deserializer()
{
internal XmlSerializer serializer = new XmlSerializer(typeof(myAPI));
EventWaitHandle MyEventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
while (!Global.IsShuttingDown)
{
MyEventWaitHandle.WaitOne(10);
XmlReader reader = XmlReader.Create("http://" + apiAddress + ":" + apiPort + "/api");
apiData = (myAPI)serializer.Deserialize(reader);
updateChannelData();
}
}
This works, but due to the rate at which I pool data, can be a bit more of a burden on the machine than I would like.
The API is fixed in stone so I cannot use UDP or COM or anything like that, only XML from a local URL.
Is there a more effective way to do this? Also the XmlReader
has no option to store the string response so I can compare it for changes thus possibly skipping updateChannelData()
if there are no changed detected, what can I do that is lightweight to add this implementation?