public void RunPubJob() { if (pubTimer.HasElapsed() >= 10) { if (zmqPubSocket != null) { StatusMessage statusMsg = new StatusMessage(); lock (pubLockObj) { foreach (KeyValuePair <int, float> x in encoderMap) { ValueMessage v = new ValueMessage { Id = x.Key, Value = x.Value }; statusMsg.Encoders.Add(v); } foreach (KeyValuePair <int, float> x in accelerometerMap) { ValueMessage v = new ValueMessage { Id = x.Key, Value = x.Value }; statusMsg.Accelerometers.Add(v); } foreach (KeyValuePair <int, float> x in gyroscopeMap) { ValueMessage v = new ValueMessage { Id = x.Key, Value = x.Value }; statusMsg.Gyroscopes.Add(v); } foreach (KeyValuePair <int, float> x in advancedMap) { ValueMessage v = new ValueMessage { Id = x.Key, Value = x.Value }; statusMsg.Advanced.Add(v); } } Console.WriteLine("Sending"); zmqPubSocket.Send(new ZFrame(statusMsg.ToByteArray())); } else { Interlocked.Increment(ref pubFailCount); if (pubFailCount >= 100) { ReInitPubSocket(); } } pubTimer.Start(); } }