Sprinkle ConfigureAwait(false) and ensure proper disposal

This commit is contained in:
Eilon Lipton 2019-10-02 14:30:24 -07:00
Родитель 6f470def7d
Коммит 23da74714e
2 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@ -25,6 +25,7 @@ namespace BlinForms.Framework
private readonly IServiceProvider _serviceProvider;
private readonly IHostApplicationLifetime _hostApplicationLifetime;
private readonly IEnumerable<IBlinFormsStartup> _blinFormsStartups;
private BlinFormsRenderer _renderer;
public BlinFormsHostedService(
IBlinFormsRootFormContent blinFormsMainForm,
@ -44,22 +45,22 @@ namespace BlinForms.Framework
{
if (_blinFormsStartups != null)
{
await Task.WhenAll(_blinFormsStartups.Select(async startup => await startup.OnStartAsync()));
await Task.WhenAll(_blinFormsStartups.Select(async startup => await startup.OnStartAsync().ConfigureAwait(false))).ConfigureAwait(false);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var renderer = new BlinFormsRenderer(_serviceProvider, _loggerFactory);
await renderer.Dispatcher.InvokeAsync(async () =>
_renderer = new BlinFormsRenderer(_serviceProvider, _loggerFactory);
await _renderer.Dispatcher.InvokeAsync(async () =>
{
var rootForm = new RootForm();
rootForm.FormClosed += OnRootFormFormClosed;
await renderer.AddComponent(_blinFormsMainForm.RootFormContentType, new ControlWrapper(rootForm));
await _renderer.AddComponent(_blinFormsMainForm.RootFormContentType, new ControlWrapper(rootForm)).ConfigureAwait(false);
Application.Run(rootForm);
});
}).ConfigureAwait(false);
}
private void OnRootFormFormClosed(object sender, FormClosedEventArgs e)
@ -70,6 +71,8 @@ namespace BlinForms.Framework
public Task StopAsync(CancellationToken cancellationToken)
{
_renderer?.Dispose();
return Task.CompletedTask;
}

Просмотреть файл

@ -41,7 +41,7 @@ namespace Emblazon
/// <returns></returns>
public async Task AddComponent<TComponent>(IElementHandler parent) where TComponent : IComponent
{
await AddComponent(typeof(TComponent), parent);
await AddComponent(typeof(TComponent), parent).ConfigureAwait(false);
}
/// <summary>
@ -64,8 +64,8 @@ namespace Emblazon
_componentIdToAdapter[componentId] = rootAdapter;
await RenderRootComponentAsync(componentId);
});
await RenderRootComponentAsync(componentId).ConfigureAwait(false);
}).ConfigureAwait(false);
}
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)