Lego.Ev3.Core.Brick.ConnectAsyncInternal C# (CSharp) Method

ConnectAsyncInternal() private method

private ConnectAsyncInternal ( TimeSpan pollingTime ) : Task
pollingTime TimeSpan
return Task
		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);
			}
		}