Ejemplo n.º 1
0
        private static void MessageThread(MLLPServer server, MeasurementSequence messageSequence, int delay, CancellationToken token, Action <Measurement> onSend)
        {
            while (!token.IsCancellationRequested)
            {
                var measurement = messageSequence.GetMeasurement();

                if (measurement != null)
                {
                    var message = BuildHL7Message(measurement.Value);

                    List <Task> tasks = new List <Task>();

                    foreach (MLLPClient client in server.Clients())
                    {
                        tasks.Add(client.SendMessageAsync(message));
                    }

                    onSend?.Invoke(measurement.Value);

                    try
                    {
                        Task.WaitAll(tasks.ToArray(), token);
                    }
                    catch {}

                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }

                token.WaitHandle.WaitOne(delay);
            }
        }
Ejemplo n.º 2
0
 public Backend()
 {
     _messageSequence = new MeasurementSequence();
     _delay           = 2000;
 }