public async Task ConnectAsync(DeviceAgent sender) { var now = DateTime.Now; var connectEvent = new BeginConnectEvent(now + TimeSpan.FromMilliseconds(SimulationBluetoothConstants.BASE_HANDSHAKE_DELAY_MILLIS), sender); await ChannelsExtensions.WriteAsync(adapterEventQueueChannel, connectEvent).ConfigureAwait(false); var timeoutEvent = new TimeoutConnectEvent(now + TimeSpan.FromMilliseconds(SimulationBluetoothConstants.HANDSHAKE_TIMEOUT_MILLIS), connectEvent); await ChannelsExtensions.WriteAsync(adapterEventQueueChannel, timeoutEvent).ConfigureAwait(false); await connectEvent.ResultBox.GetResultAsync().ConfigureAwait(false); }
public void Connect(int outChannelNumber, CancellationToken cancellationToken) { try { ClearException(); if (!ConnectState) { BeginConnectEvent?.Invoke(this, new EventArgs()); commands.Connect(outChannelNumber, cancellationToken); taskCycleRead = StartCycleRead(); ConnectState = true; } ConnectEvent?.Invoke(this, new EventArgs()); } catch (OperationCanceledException) { throw; } catch (Exception ex) { throw new PressSystemException(ex.Message); } }
public TimeoutConnectEvent(DateTime time, BeginConnectEvent beginEvent) : base(time) { BeginEvent = beginEvent; }