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

DemoBytom / DemoEngine / 19463301765

18 Nov 2025 10:46AM UTC coverage: 26.251% (+1.6%) from 24.615%
19463301765

push

coveralls.net

web-flow
Merge pull request #462 from DemoBytom/feature/dx12-arm64

DirectX12 and Windows on Arm migration

530 of 2019 relevant lines covered (26.25%)

0.28 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.Features.StaThread;
6
using Demo.Engine.Core.Interfaces;
7
using Demo.Engine.Core.Interfaces.Platform;
8
using Demo.Engine.Core.Interfaces.Rendering;
9
using Microsoft.Extensions.DependencyInjection;
10
using Microsoft.Extensions.Hosting;
11
using Microsoft.Extensions.Logging;
12

13
namespace Demo.Engine.Core.Services;
14

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

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

37
    public Task StartAsync(CancellationToken cancellationToken)
38
    {
39
        _logger.LogInformation("{serviceName} starting! v{version}", _serviceName, _version);
×
40
        _executingTask = DoWorkAsync();
×
41

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

47
    public async Task StopAsync(CancellationToken cancellationToken)
48
    {
49
        _logger.LogInformation("{serviceName} stopping!", _serviceName);
×
50

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

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

62
    private async Task DoWorkAsync()
63
    {
64
        try
65
        {
66
            using var scope = _scopeFactory.CreateScope();
×
67
            var serviceProvider = scope.ServiceProvider;
×
68
            var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
×
69
            var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
×
70

71
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
72
            var executeAsync = mainLoopService.ExecutingTask;
×
73

74
            var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
×
75
            var runStaThread = staThreadService.ExecutingTask;
×
76

77
            await Task.WhenAll(
×
78
                [
×
79
                    executeAsync,
×
80
                    runStaThread
×
81
                ]);
×
82
        }
×
83
        catch (OperationCanceledException)
×
84
        {
85
            _mainLoopLifetime.Cancel();
×
86
        }
×
87
        catch (Exception ex)
×
88
        {
89
            _logger.LogCritical(ex, "{serviceName} failed with error! {errorMessage}", _serviceName, ex.Message);
×
90
        }
×
91
        finally
92
        {
93
            if (!_stopRequested)
×
94
            {
95
                _hostApplicationLifetime.StopApplication();
×
96
            }
97
        }
98
    }
×
99

100
    private void Dispose(bool disposing)
101
    {
102
        if (!_disposedValue)
×
103
        {
104
            if (disposing)
×
105
            {
106
                _hostApplicationLifetime.StopApplication();
×
107
            }
108

109
            _disposedValue = true;
×
110
        }
111
    }
×
112

113
    public void Dispose()
114
    {
115
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
116
        Dispose(disposing: true);
×
117
        GC.SuppressFinalize(this);
×
118
    }
×
119
}
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