private static async Task MessageCallback(Message m) { for (var i = Subscribers.Count - 1; i >= 0; i--) { try { await Subscribers[i].WriteLineAsync("data:" + JsonConvert.SerializeObject(m) + "\n"); await Subscribers[i].WriteLineAsync(""); await Subscribers[i].FlushAsync(); } catch (Exception) { lock (locker) { Subscribers.RemoveAt(i); } } } }
public async Task Post(Message m) { m.DateTime = DateTime.Now; await MessageCallback(m); }