Nikita Tsukanov 2 лет назад
Родитель
Сommit
ee445f2197

+ 1 - 3
native/Avalonia.Native/src/OSX/platformthreading.mm

@@ -79,13 +79,11 @@ static double distantFutureInterval = (double)50*365*24*3600;
         bool signaled;
         @synchronized (self) {
             signaled = self->_signaled;
+            self->_signaled = false;
         }
         if(signaled)
         {
             self->_events->Signaled();
-            @synchronized (self) {
-                self->_signaled = false;
-            }
         }
     });
     CFRunLoopAddObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes);

+ 7 - 1
src/Avalonia.Base/Threading/Dispatcher.Queue.cs

@@ -124,7 +124,13 @@ public partial class Dispatcher
             else if (_pendingInputImpl?.CanQueryPendingInput == true)
             {
                 if (!_pendingInputImpl.HasPendingInput)
-                    ExecuteJob(job);
+                {
+                    // On platforms like macOS HasPendingInput check might trigger a timer
+                    // which would result in reentrancy here, so we check if the job 
+                    // hasn't been executed yet
+                    if (job.Status == DispatcherOperationStatus.Pending)
+                        ExecuteJob(job);
+                }
                 else
                 {
                     RequestBackgroundProcessing();