コード例 #1
0
        private async Task PollOnInvoices(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                ServiceLogger.Information("Polling ...");

                await Task.Delay(2000);
            }
        }
コード例 #2
0
        public Task ProcessInvoices(CancellationToken cancellationToken)
        {
            return(Task.Run(() =>
            {
                Policy.Handle <Exception>()
                .WaitAndRetryForeverAsync(i => TimeSpan.FromSeconds(2), (ex, span) =>
                {
                    ServiceLogger.Information("Error when polling invoices!" + ex.Message);
                })

                .ExecuteAsync(async ct =>
                {
                    ServiceLogger.Information("Starting to poll for new invoices.");
                    await PollOnInvoices(cancellationToken);
                }, cancellationToken);
            }, cancellationToken));
        }