public static Task <string> ForceBroadcast( this IBlockchainTransaction tx, IBlockchainApi blockchainApi, Swap swap, TimeSpan interval, Action <Swap, string, CancellationToken> completionHandler = null, CancellationToken cancellationToken = default) { return(Task.Run(async() => { try { while (!cancellationToken.IsCancellationRequested) { var broadcastResult = await blockchainApi .TryBroadcastAsync(tx, cancellationToken: cancellationToken) .ConfigureAwait(false); if (!broadcastResult.HasError) { if (broadcastResult.Value != null) { completionHandler?.Invoke(swap, broadcastResult.Value, cancellationToken); return broadcastResult.Value; } } else { Log.Error("Error while broadcast {@currency} tx with. Code: {@code}. Description: {@desc}", tx.Currency, broadcastResult.Error.Code, broadcastResult.Error.Description); } await Task.Delay(interval, cancellationToken) .ConfigureAwait(false); } } catch (OperationCanceledException) { Log.Debug("ForceBroadcast canceled."); } catch (Exception e) { Log.Error(e, "Error while broadcast {@currency} tx.", tx.Currency); } return null; }, cancellationToken)); }