Files
SPT-Server-Build/SPTarkov.Server/Services/SptServerBackgroundService.cs
T
clodanSPT 1af50bfd34 Application cleanup (#485)
* Changed application to use background services and removed hacky http server startup

* Small improvements and method removals

* Removed Core dependency on Web application SDK

* Fixed wrong imported type

---------

Co-authored-by: Alex <clodanSPT@hotmail.com>
Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com>
2025-07-18 16:21:24 +01:00

34 lines
1.1 KiB
C#

using System.Runtime;
using SPTarkov.Server.Core.Loaders;
using SPTarkov.Server.Core.Models.Spt.Mod;
using SPTarkov.Server.Core.Utils;
namespace SPTarkov.Server.Services;
public class SptServerBackgroundService(IReadOnlyList<SptMod> loadedMods, BundleLoader bundleLoader, App app) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (ProgramStatics.MODS())
{
foreach (var mod in loadedMods)
{
if (mod.ModMetadata?.IsBundleMod == true)
{
// Convert to relative path
var relativeModPath = Path.GetRelativePath(Directory.GetCurrentDirectory(), mod.Directory)
.Replace('\\', '/');
bundleLoader.AddBundles(relativeModPath);
}
}
}
await app.InitializeAsync();
// Run garbage collection now the server is ready to start
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true);
}
}