private void Initialize(bool force = false)
{
if (this.initializeCalled && !force)
{
return;
}
this.initializeCalled = true;
this.cancellationTokenSource?.Cancel();
this.cancellationTokenSource = new CancellationTokenSource();
this.listener?.Stop();
var token = this.cancellationTokenSource.Token;
this.listenTask = Task.Factory.StartNew(
() => this.Listen(token),
token,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
}