From 44bec40a86a90a600efea0b20c5cc06dc513edb9 Mon Sep 17 00:00:00 2001 From: Patrick Grote Date: Thu, 9 May 2024 23:13:44 +0200 Subject: [PATCH] Grr --- ArtNetSharp/Communication/AbstractInstance.cs | 12 +++--------- ArtNetTests/LoopTests/ControllerToControllerTests.cs | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/ArtNetSharp/Communication/AbstractInstance.cs b/ArtNetSharp/Communication/AbstractInstance.cs index d906944..6f987b6 100644 --- a/ArtNetSharp/Communication/AbstractInstance.cs +++ b/ArtNetSharp/Communication/AbstractInstance.cs @@ -9,7 +9,6 @@ using System.Data; using System.Diagnostics; using System.Linq; -using System.Reflection.Emit; using System.Threading; using System.Threading.Tasks; using System.Timers; @@ -211,11 +210,7 @@ protected AbstractInstance() }; _timerSendPoll.Elapsed += _timerSendPoll_Elapsed; - sendDMXThread = new Thread(sendAllArtDMX); - sendDMXThread.Name = "Send DMX Thread"; - sendDMXThread.IsBackground = true; - sendDMXThread.Priority = ThreadPriority.AboveNormal; - sendDMXThread.Start(); + Task.Run(sendAllArtDMX); KnownRDMUIDs = knownRDMUIDs.Values.ToList().AsReadOnly(); } @@ -500,7 +495,7 @@ public async Task sendArtDMX(IPv4Address ipAddress, PortAddress portAddress, byt await TrySendPacket(artDMX, ipAddress); } Stopwatch sw = Stopwatch.StartNew(); - private async void sendAllArtDMX() + private async Task sendAllArtDMX() { const double dmxRefreshTime = 1000 / 44.0; // Spec 1.4dh page 56 const double dmxKeepAliveTime = 800; // Spec 1.4dh page 53 @@ -509,7 +504,6 @@ private async void sendAllArtDMX() if (this.IsDeactivated) continue; - await Task.Delay(5); try { var ports = RemoteClientsPorts.Where(port => port.OutputPortAddress.HasValue && !port.Timouted()).ToList(); @@ -521,6 +515,7 @@ private async void sendAllArtDMX() if (sendDMXBuffer.TryGetValue(port.OutputPortAddress.Value, out DMXSendBag bag)) if ((bag.Updated && (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxRefreshTime) || (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxKeepAliveTime) { + bag.LastSended = DateTime.UtcNow; PortConfig config = portConfigs.FirstOrDefault(pc => PortAddress.Equals(pc.PortAddress, port.OutputPortAddress)); byte sourcePort = config?.PortNumber ?? 0; await sendArtDMX(port, sourcePort, bag.Data, bag.GetSequence(), config?.ForceBroadcast ?? false); @@ -532,7 +527,6 @@ private async void sendAllArtDMX() await sendArtDMX(ip, config.PortAddress, sourcePort, bag.Data, bag.GetSequence()); sended++; } - bag.LastSended = DateTime.UtcNow; } } catch (Exception e) { Logger.LogError(e); } diff --git a/ArtNetTests/LoopTests/ControllerToControllerTests.cs b/ArtNetTests/LoopTests/ControllerToControllerTests.cs index 234aa9b..fb40a39 100644 --- a/ArtNetTests/LoopTests/ControllerToControllerTests.cs +++ b/ArtNetTests/LoopTests/ControllerToControllerTests.cs @@ -222,8 +222,8 @@ public async Task TestSendDMXTiming() { Assert.That(syncFlag, Is.True); Assert.That(receivedFlag, Is.True); - Assert.That(syncRate.Average(), Is.InRange(30, 60)); - Assert.That(refreshRate.Average(), Is.InRange(30, 60)); + Assert.That(syncRate.Average(), Is.InRange(44, 60)); + Assert.That(refreshRate.Average(), Is.InRange(44, 60)); }); } }