Browse Source

Discard the task result in Timer_Elapsed.

Resolve #6385
pull/6417/head
maliming 6 years ago
parent
commit
8544f954a7
  1. 18
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AsyncPeriodicBackgroundWorkerBase.cs
  2. 2
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
  3. 12
      framework/src/Volo.Abp.Cli/Volo/Abp/Cli/Program.cs
  4. 10
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
  5. 4
      framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs
  6. 4
      framework/test/Volo.Abp.BlobStoring.Aws.Tests/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsTestModule.cs

18
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AsyncPeriodicBackgroundWorkerBase.cs

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

2
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs

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

12
framework/src/Volo.Abp.Cli/Volo/Abp/Cli/Program.cs

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

10
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs

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

4
framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs

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

4
framework/test/Volo.Abp.BlobStoring.Aws.Tests/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsTestModule.cs

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

Loading…
Cancel
Save