Discard the task result in Timer_Elapsed.

Resolve #6385
pull/6417/head
maliming 5 years ago
parent 1b36843910
commit 8544f954a7

@ -35,22 +35,24 @@ namespace Volo.Abp.BackgroundWorkers
}
private void Timer_Elapsed(object sender, System.EventArgs e)
{
// Discard the result
_ = DoWorkAsync();
}
private async Task DoWorkAsync()
{
using (var scope = ServiceScopeFactory.CreateScope())
{
try
{
AsyncHelper.RunSync(
() => DoWorkAsync(new PeriodicBackgroundWorkerContext(scope.ServiceProvider))
);
await DoWorkAsync(new PeriodicBackgroundWorkerContext(scope.ServiceProvider));
}
catch (Exception ex)
{
AsyncHelper.RunSync(
() => scope.ServiceProvider
.GetRequiredService<IExceptionNotifier>()
.NotifyAsync(new ExceptionNotificationContext(ex))
);
await scope.ServiceProvider
.GetRequiredService<IExceptionNotifier>()
.NotifyAsync(new ExceptionNotificationContext(ex));
Logger.LogException(ex);
}

@ -1029,7 +1029,7 @@ namespace Volo.Abp.Caching
protected virtual void HandleException(Exception ex)
{
AsyncHelper.RunSync(() => HandleExceptionAsync(ex));
_ = HandleExceptionAsync(ex);
}
protected virtual async Task HandleExceptionAsync(Exception ex)

@ -3,13 +3,13 @@ using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Events;
using System.IO;
using Volo.Abp.Threading;
using System.Threading.Tasks;
namespace Volo.Abp.Cli
{
public class Program
{
private static void Main(string[] args)
private static async Task Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
@ -37,11 +37,9 @@ namespace Volo.Abp.Cli
{
application.Initialize();
AsyncHelper.RunSync(
() => application.ServiceProvider
.GetRequiredService<CliService>()
.RunAsync(args)
);
await application.ServiceProvider
.GetRequiredService<CliService>()
.RunAsync(args);
application.Shutdown();
}

@ -38,7 +38,7 @@ namespace Volo.Abp.RabbitMQ
public RabbitMqMessageConsumer(
IConnectionPool connectionPool,
AbpTimer timer,
AbpTimer timer,
IExceptionNotifier exceptionNotifier)
{
ConnectionPool = connectionPool;
@ -119,7 +119,7 @@ namespace Volo.Abp.RabbitMQ
catch (Exception ex)
{
Logger.LogException(ex, LogLevel.Warning);
AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning));
_ = ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning);
}
}
@ -186,7 +186,7 @@ namespace Volo.Abp.RabbitMQ
catch (Exception ex)
{
Logger.LogException(ex, LogLevel.Warning);
AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning));
_ = ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning);
}
}
@ -204,7 +204,7 @@ namespace Volo.Abp.RabbitMQ
catch (Exception ex)
{
Logger.LogException(ex);
await ExceptionNotifier.NotifyAsync(ex);
_ = ExceptionNotifier.NotifyAsync(ex);
}
}
@ -222,7 +222,7 @@ namespace Volo.Abp.RabbitMQ
catch (Exception ex)
{
Logger.LogException(ex, LogLevel.Warning);
AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning));
_ = ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning);
}
}

@ -101,7 +101,7 @@ namespace Volo.Abp.Threading
catch(Exception ex)
{
Logger.LogException(ex);
AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex));
_ = ExceptionNotifier.NotifyAsync(ex);
}
finally
{
@ -118,4 +118,4 @@ namespace Volo.Abp.Threading
}
}
}
}
}

@ -69,7 +69,7 @@ namespace Volo.Abp.BlobStoring.Aws
private async Task DeleteBucketAsync(ApplicationShutdownContext context)
{
var amazonS3Client = await context.ServiceProvider.GetService<IAmazonS3ClientFactory>()
var amazonS3Client = await context.ServiceProvider.GetRequiredService<IAmazonS3ClientFactory>()
.GetAmazonS3Client(_configuration);
if (await AmazonS3Util.DoesS3BucketExistV2Async(amazonS3Client, _randomContainerName))
@ -89,4 +89,4 @@ namespace Volo.Abp.BlobStoring.Aws
}
}
}
}
}

Loading…
Cancel
Save