public void AddConnection(string clientId, Socket socket) { // ConcurrentDictionary is not guaranteed to invoke add or update method once, so we use lazy behavior Connections.AddOrUpdate(clientId, new Lazy <Socket>(() => socket, LazyThreadSafetyMode.ExecutionAndPublication), (key, oldValue) => new Lazy <Socket>(() => socket, LazyThreadSafetyMode.ExecutionAndPublication)); }
public BluetoothLEConnectionManager() { Watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; Watcher.Received += async(w, btAdv) => { var device = await BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress); if (device != null) { Debug.WriteLine($"BLEWATCHER Found: {device.DeviceId}"); if (!Connections.ContainsKey(device.DeviceId)) { Connections.AddOrUpdate(device.DeviceId, new BluetoothLEConnection(device), (key, value) => value); } } }; Watcher.Start(); }
public override Task OnConnectedAsync() { _logger.LogDebug("New connection. Count: {count}", Connections.Count); Connections.AddOrUpdate(Context.ConnectionId, Clients.Caller, (k, v) => Clients.Caller); return(base.OnConnectedAsync()); }