private async Task ConnectAsyncInternal(TimeSpan pollingTime)
{
_tokenSource = new CancellationTokenSource();
await _comm.ConnectAsync();
await _directCommand.StopMotorAsync(OutputPort.All, false);
if(pollingTime != TimeSpan.Zero)
{
Task t = Task.Factory.StartNew(async () =>
{
while(!_tokenSource.IsCancellationRequested)
{
await PollSensorsAsync();
await Task.Delay(pollingTime, _tokenSource.Token);
}
await _directCommand.StopMotorAsync(OutputPort.All, false);
}, _tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}
}