Skip to content

Commit

Permalink
fix cancellation exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Mar 31, 2024
1 parent 39a8228 commit 18aa0b0
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions Project-Aurora/AuroraCommon/Utils/MemorySharedEventThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private Thread CreateThread()
_semaphore.Wait(CancelToken.Token);
ThreadCallback();
}
catch (OperationCanceledException)
{
// end the thread
}
finally
{
_semaphore.Release();
Expand All @@ -86,35 +90,35 @@ private Thread CreateThread()
thread.Start();
Thread.Yield();
return thread;

void ThreadCallback(){
if (_handles.Length <= 1)
}

private void ThreadCallback(){
if (_handles.Length <= 1)
{
// stop thread if only handle is cancel token
return;
}
while (true)
{
if (CancelToken.IsCancellationRequested)
{
// stop thread if only handle is cancel token
return;
}
while (true)
var i = WaitHandle.WaitAny(_handles);
switch (i)
{
if (CancelToken.IsCancellationRequested)
{
case 0:
return;
}
var i = WaitHandle.WaitAny(_handles);
switch (i)
{
case 0:
return;
default:
if (i >= _handles.Length)
{
break;
}
Task.Run(() =>
{
_actions[i].Invoke();
});
default:
if (i >= _handles.Length)
{
break;
}
}
Task.Run(() =>
{
_actions[i].Invoke();
});
break;
}
}
}
Expand Down

0 comments on commit 18aa0b0

Please sign in to comment.