Skip to content

Commit

Permalink
Make sure there are no multithreading deadlocks :)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnccd committed Apr 23, 2024
1 parent 7766490 commit 74358de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MEE7-Discord-Bot/BuildDate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24.04.2024 0:26:39,02
24.04.2024 0:38:33,29
10 changes: 7 additions & 3 deletions MEE7-Discord-Bot/Commands/Lighthouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public override void Execute(IMessage message)
var split = message.Content.Split(' ');
if (split.Length >= 3 && split[1] == "set-token")
{
cancelTokenSource.Cancel();
lighthouseThread.Wait();

lock (images)
{
cancelTokenSource.Cancel();
lighthouseThread.Wait();
token = split[2];
cancelTokenSource.TryReset();
cancelTokenSource = new();
cancelToken = cancelTokenSource.Token;
StartSenderLoop();
}
Expand Down Expand Up @@ -107,6 +108,9 @@ public void StartSenderLoop()
{
sw.Restart();
if (cancelToken.IsCancellationRequested)
break;
lock (images)
{
webSocketClient.SendAsync(PackMessage(imageCounter), WebSocketMessageType.Binary, true, default)
Expand Down

0 comments on commit 74358de

Please sign in to comment.