Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/D2BotNG/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ private static void Main(string[] args)
// EngineHostedService.StartAsync (and any handoff RehydrateAsync inside it) reads
// MessageWindow.Handle, so it must be valid by then. In GUI mode, MainForm no
// longer switches the handle when it loads — the message-only window owns it
// for the full process lifetime.
// for the full process lifetime. The window runs on its own pump thread, so this
// returns once the handle exists and nothing here shares a pump with it: senders
// block on SendMessageW, and the UI thread below is about to host WebView2.
var messageWindow = app.Services.GetRequiredService<MessageWindow>();
messageWindow.CreateMessageOnlyWindow();

Expand Down
18 changes: 17 additions & 1 deletion src/D2BotNG/Services/D2BSMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,24 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("D2BS message handler started");

await foreach (var msg in _messageWindow.Messages.ReadAllAsync(stoppingToken))
await foreach (var raw in _messageWindow.Messages.ReadAllAsync(stoppingToken))
{
// Decoding and JSON parsing happen here rather than in the WndProc: the sending game
// is blocked in SendMessageW for the whole of that call, and the rest of the fleet is
// queued behind it. Parse returns null for a payload it cannot read (already logged),
// and the buffer goes back to the pool either way.
D2BSMessage? msg;
try
{
msg = _messageWindow.Parse(raw);
}
finally
{
raw.Release();
}

if (msg == null) continue;

try
{
await HandleMessageAsync(msg);
Expand Down
Loading
Loading