/// <summary> /// Queue a string to broadcast /// </summary> public void QueueStringToBroadcast(string broadcast) { if (RunTask != null) { StringsToBroadcast.Enqueue(broadcast); NotifyDataToBroadcast.Release(); } }
/// <summary> /// Run function /// </summary> private async Task RunDataBroadcastServerAsync(CancellationToken cancelToken) { try { var info = new StreamInfo("bhStatus", "bhStatus", 1, IRREGULAR_RATE, channel_format_t.cf_string, NetworkUtilities.GetHostName()); info.desc().append_child_value("boardId", BoardId.ToString()); info.desc().append_child_value("sampleRate", SampleRate.ToString()); // create UDP client using (var outlet = new StreamOutlet(info)) { try { while (!cancelToken.IsCancellationRequested) { await NotifyDataToBroadcast.WaitAsync(cancelToken); while (!StringsToBroadcast.IsEmpty) { try { StringsToBroadcast.TryDequeue(out var broadcastString); outlet.push_sample(new string[] { broadcastString }); } catch (Exception ex) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", ex, LogLevel.ERROR)); } } } } catch (OperationCanceledException) { } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", e, LogLevel.ERROR)); } } } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", e, LogLevel.ERROR)); } }