• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemoBytom / DemoEngine / 24746555599

21 Apr 2026 09:07PM UTC coverage: 30.388% (-0.2%) from 30.6%
24746555599

push

coveralls.net

DemoBytom
WIP new WindowsMessagePump

1283 of 4222 relevant lines covered (30.39%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Demo.Engine.Core/Services/EngineService.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Reflection;
5
using Demo.Engine.Core.Interfaces;
6
using Demo.Engine.Core.Requests;
7
using Mediator;
8
using Microsoft.Extensions.DependencyInjection;
9
using Microsoft.Extensions.Hosting;
10
using Microsoft.Extensions.Logging;
11

12
namespace Demo.Engine.Core.Services;
13

14
internal sealed class EngineService(
×
15
    ILogger<EngineService> logger,
×
16
    IHostApplicationLifetime hostApplicationLifetime,
×
17
    IServiceScopeFactory scopeFactory,
×
18
    IMediator mediator)
×
19
    : IHostedService,
20
      IDisposable
21
{
22
    private readonly ILogger<EngineService> _logger = logger;
×
23
    private readonly IHostApplicationLifetime _hostApplicationLifetime = hostApplicationLifetime;
×
24
    private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
×
25
    private readonly IMediator _mediator = mediator;
×
26
    private readonly string _serviceName = "Engine";
×
27
    private Task? _executingTask;
28
    private bool _stopRequested;
29
    private bool _disposedValue;
30

31
    private readonly string _version = Assembly
×
32
        .GetEntryAssembly()
×
33
        ?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
×
34
        ?.InformationalVersion ?? "0.0.0";
×
35

36
    public Task StartAsync(CancellationToken cancellationToken)
37
    {
38
        _logger.LogServiceIsStarting(_serviceName, _version);
×
39
        _executingTask = DoWorkAsync();
×
40

41
        return _executingTask.IsCompleted
×
42
            ? _executingTask
×
43
            : Task.CompletedTask;
×
44
    }
45

46
    public async Task StopAsync(CancellationToken cancellationToken)
47
    {
48
        _logger.LogServiceStopping(_serviceName);
×
49

50
        _stopRequested = true;
×
51
        if (_executingTask is null)
×
52
        {
53
            return;
×
54
        }
55

56
        _ = await Task.WhenAny(
×
57
            _executingTask,
×
58
            Task.Delay(Timeout.Infinite, cancellationToken));
×
59
    }
×
60

61
    private async Task DoWorkAsync()
62
    {
63
        await using var scope = _scopeFactory.CreateAsyncScope();
×
64
        var serviceProvider = scope.ServiceProvider;
×
65
        var mainLoopLifetime = serviceProvider.GetService<IMainLoopLifetime>();
×
66

67
        try
68
        {
69
            //var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
70
            //var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
71

72
            _ = await _mediator.Send(new CompileShaders(), _hostApplicationLifetime.ApplicationStopping);
×
73
            _ = await _mediator.Send(new LoadShadersRequest(), _hostApplicationLifetime.ApplicationStopping);
×
74

75
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
76
            var executeAsync = mainLoopService.ExecutingTask;
×
77

78
            //var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
79
            //var runStaThread = staThreadService.ExecutingTask;
80

81
            await Task.WhenAll(
×
82
                [
×
83
                    executeAsync/*,
×
84
                    runStaThread*/
×
85
                ]);
×
86
        }
×
87
        catch (OperationCanceledException)
×
88
        {
89
            mainLoopLifetime?.Cancel();
×
90
        }
×
91
        catch (Exception ex)
×
92
        {
93
            _logger.LogServiceFailedWithError(ex, _serviceName);
×
94
        }
×
95
        finally
96
        {
97
            if (!_stopRequested)
×
98
            {
99
                //await Task.Delay(10_000);
100
                await scope.DisposeAsync();
×
101
                _hostApplicationLifetime.StopApplication();
×
102
            }
103
        }
104
    }
×
105

106
    private void Dispose(bool disposing)
107
    {
108
        if (!_disposedValue)
×
109
        {
110
            if (disposing)
×
111
            {
112
                _hostApplicationLifetime.StopApplication();
×
113
            }
114

115
            _disposedValue = true;
×
116
        }
117
    }
×
118

119
    public void Dispose()
120
    {
121
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
122
        Dispose(disposing: true);
×
123
        GC.SuppressFinalize(this);
×
124
    }
×
125
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc